完成openrec源的获取.
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/474420502/hunter"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
var targetTypeUser = "openrec_user"
|
||||
@@ -32,7 +31,7 @@ func (oer *OpenrecExtratorRanking) Execute(cxt *hunter.TaskContext) {
|
||||
|
||||
for {
|
||||
|
||||
source, err := store.Pop(targetTypeRanking)
|
||||
source, err := store.Pop(targetTypeUser)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
@@ -42,52 +41,59 @@ func (oer *OpenrecExtratorRanking) Execute(cxt *hunter.TaskContext) {
|
||||
return
|
||||
}
|
||||
|
||||
result := gjson.Parse(source.GetSource().String)
|
||||
if result.IsArray() {
|
||||
for _, User := range result.Array() {
|
||||
userid := User.Get("channel.id").String()
|
||||
ext := make(map[string]interface{})
|
||||
userSource := &intimate.Source{}
|
||||
userid := source.GetSource().String
|
||||
userUrl := "https://www.openrec.tv/user/" + userid
|
||||
userSource.SetUrl(userUrl)
|
||||
|
||||
wf := cxt.Session().Get("https://www.openrec.tv/user/" + userid)
|
||||
resp, err := wf.Execute()
|
||||
source.SetUpdateTime(time.Now())
|
||||
wf := cxt.Session().Get(userUrl)
|
||||
resp, err := wf.Execute()
|
||||
source.SetUpdateTime(time.Now())
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
source.SetOperator(int32(intimate.OperatorError))
|
||||
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
|
||||
continue
|
||||
}
|
||||
|
||||
ext["user"] = string(resp.Content())
|
||||
|
||||
wf = cxt.Session().Get("https://www.openrec.tv/user/" + userid + "/supporters")
|
||||
resp, err = wf.Execute()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
source.SetOperator(int32(intimate.OperatorError))
|
||||
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
|
||||
continue
|
||||
}
|
||||
ext["user_supporters"] = string(resp.Content())
|
||||
|
||||
extJsonBytes, err := json.Marshal(ext)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
source.SetOperator(int32(intimate.OperatorError))
|
||||
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
|
||||
continue
|
||||
}
|
||||
|
||||
source.SetOperator(int32(intimate.OperatorOK))
|
||||
source.SetExt(string(extJsonBytes))
|
||||
|
||||
store.Update(source)
|
||||
}
|
||||
} else {
|
||||
log.Println("array error:", result.Str)
|
||||
source.SetOperator(int32(intimate.OperatorError))
|
||||
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
|
||||
continue
|
||||
}
|
||||
|
||||
ext := make(map[string]interface{})
|
||||
|
||||
ext["user"] = string(resp.Content())
|
||||
|
||||
wf = cxt.Session().Get(userUrl + "/supporters")
|
||||
resp, err = wf.Execute()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
source.SetOperator(int32(intimate.OperatorError))
|
||||
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
|
||||
continue
|
||||
}
|
||||
ext["user_supporters"] = string(resp.Content())
|
||||
|
||||
wf = cxt.Session().Get("https://www.openrec.tv/live/" + userid)
|
||||
resp, err = wf.Execute()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
source.SetOperator(int32(intimate.OperatorError))
|
||||
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
|
||||
continue
|
||||
}
|
||||
ext["user_live"] = string(resp.Content())
|
||||
|
||||
extJsonBytes, err := json.Marshal(ext)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
source.SetOperator(int32(intimate.OperatorError))
|
||||
source.SetErrorMsg(sql.NullString{String: err.Error(), Valid: true})
|
||||
continue
|
||||
}
|
||||
|
||||
source.SetOperator(int32(intimate.OperatorOK))
|
||||
source.SetExt(string(extJsonBytes))
|
||||
store.Update(source)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user