2020-07-08 10:57:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-07-09 03:38:51 +00:00
|
|
|
"database/sql"
|
|
|
|
"encoding/json"
|
2020-07-08 10:57:57 +00:00
|
|
|
"intimate"
|
|
|
|
"log"
|
2020-07-09 03:38:51 +00:00
|
|
|
"time"
|
2020-07-08 10:57:57 +00:00
|
|
|
|
|
|
|
"github.com/474420502/hunter"
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
)
|
|
|
|
|
|
|
|
var targetTypeUser = "openrec_user"
|
|
|
|
var targetTypeRanking = "openrec_ranking"
|
|
|
|
var oer *OpenrecExtratorRanking
|
|
|
|
|
|
|
|
// store 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql
|
|
|
|
var store *intimate.Store = intimate.NewStore("source_openrec")
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
oer = &OpenrecExtratorRanking{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenrecExtratorRanking 获取用户信息
|
|
|
|
type OpenrecExtratorRanking struct {
|
|
|
|
// Store *intimate.Store
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute 执行方法
|
|
|
|
func (oer *OpenrecExtratorRanking) Execute(cxt *hunter.TaskContext) {
|
|
|
|
|
2020-07-09 03:38:51 +00:00
|
|
|
for {
|
|
|
|
|
|
|
|
source, err := store.Pop(targetTypeRanking)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if source == nil {
|
|
|
|
return
|
|
|
|
}
|
2020-07-08 10:57:57 +00:00
|
|
|
|
|
|
|
result := gjson.Parse(source.GetSource().String)
|
|
|
|
if result.IsArray() {
|
|
|
|
for _, User := range result.Array() {
|
|
|
|
userid := User.Get("channel.id").String()
|
2020-07-09 03:38:51 +00:00
|
|
|
ext := make(map[string]interface{})
|
|
|
|
|
|
|
|
wf := cxt.Session().Get("https://www.openrec.tv/user/" + userid)
|
|
|
|
resp, err := wf.Execute()
|
|
|
|
source.SetUpdateTime(time.Now())
|
|
|
|
|
|
|
|
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())
|
2020-07-08 10:57:57 +00:00
|
|
|
|
2020-07-09 03:38:51 +00:00
|
|
|
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())
|
2020-07-08 10:57:57 +00:00
|
|
|
|
2020-07-09 03:38:51 +00:00
|
|
|
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)
|
2020-07-08 10:57:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Println("array error:", result.Str)
|
|
|
|
}
|
|
|
|
|
2020-07-09 03:38:51 +00:00
|
|
|
}
|
2020-07-08 10:57:57 +00:00
|
|
|
}
|