1.最后一次数据存储结构重构.

2.数据最接近需求方.
This commit is contained in:
eson
2020-07-20 18:13:54 +08:00
parent 6369387179
commit f0f83a9f00
9 changed files with 296 additions and 140 deletions

View File

@@ -20,8 +20,11 @@ import (
var oer *OpenrecExtratorRanking
// store 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql
var store *intimate.SourceStore = intimate.NewSourceStore(string(intimate.STOpenrec))
// sstore 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql
var sstore *intimate.StoreSource = intimate.NewStoreSource(string(intimate.STOpenrec))
// estore 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_extractor.sql
var estore *intimate.StoreExtractor = intimate.NewStoreExtractor()
func init() {
oer = &OpenrecExtratorRanking{}
@@ -48,9 +51,9 @@ func (oer *OpenrecExtratorRanking) Execute(cxt *hunter.TaskContext) {
for atomic.LoadInt32(&loop) > 0 {
source, err := store.Pop(string(intimate.TTOpenrecUser))
streamer, err := estore.Pop(string(intimate.Popenrec))
if source == nil || err != nil {
if streamer == nil || err != nil {
if err != lasterr {
log.Println(err, lasterr)
lasterr = err
@@ -59,22 +62,31 @@ func (oer *OpenrecExtratorRanking) Execute(cxt *hunter.TaskContext) {
continue
}
userId := source.Source.String
userUrl := "https://www.openrec.tv/user/" + userId
userId := streamer.UserId
var updateUrl map[string]string
err = json.Unmarshal(streamer.UpdateUrl.([]byte), &updateUrl)
if err != nil {
log.Println(err)
continue
}
// Check Userid
userUrl := updateUrl["user"]
tp := cxt.Session().Get(userUrl)
resp, err := tp.Execute()
source.UpdateTime = sql.NullTime{Time: time.Now(), Valid: true}
streamer.UpdateTime = sql.NullTime{Time: time.Now(), Valid: true}
if err != nil {
log.Println(err)
store.UpdateError(source, err)
estore.UpdateError(streamer, err)
continue
}
cookies := cxt.Session().GetCookies(tp.GetParsedURL())
scurl := "https://www.openrec.tv/viewapp/api/v6/supporters?identify_id=sumomo_xqx&month=&Uuid=B96EE988-E3A2-4A44-A543-611A8B4BC683&Token=46598c320408bd69ae3c63298f6f4a3a97354175&Random=AZVXNAAXQVMOSVWNDPIQ&page_number=1 -H 'accept: application/json, text/javascript, */*; q=0.01' -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' -H 'cookie: uuid=B96EE988-E3A2-4A44-A543-611A8B4BC683;' --compressed"
scurl := updateUrl["supporters"]
curl := gcurl.ParseRawCURL(scurl)
supportersSession := curl.CreateSession()
@@ -134,25 +146,31 @@ func (oer *OpenrecExtratorRanking) Execute(cxt *hunter.TaskContext) {
ext["supporters"] = supporters
ext["user"] = string(resp.Content())
tp = cxt.Session().Get("https://www.openrec.tv/live/" + userId)
liveUrl := updateUrl["live"]
tp = cxt.Session().Get(liveUrl)
resp, err = tp.Execute()
if err != nil {
log.Println(err)
store.UpdateError(source, err)
estore.UpdateError(streamer, err)
continue
}
ext["user_live"] = string(resp.Content())
ext["live"] = string(resp.Content())
extJsonBytes, err := json.Marshal(ext)
if err != nil {
log.Println(err)
store.UpdateError(source, err)
estore.UpdateError(streamer, err)
continue
}
source.Operator = int32(intimate.OperatorOK)
streamer.Operator = int32(intimate.OperatorOK)
source := &intimate.Source{}
source.TargetType = string(intimate.TTOpenrecUser)
source.Ext = string(extJsonBytes)
store.Update(source)
sstore.Insert(source)
estore.UpdateOperator(streamer)
}
}