TODO: openrec user data. isource update interface

This commit is contained in:
eson 2020-07-08 18:57:57 +08:00
parent 5cbb17d6d4
commit 0a2a134511
16 changed files with 105 additions and 5 deletions

View File

@ -82,8 +82,8 @@ func (store *Store) Pop(targetType string, operators ...int32) (IUpdateSource, e
}
}
log.Println(selectSQL + ` limit 1 for update`)
row := tx.QueryRow(selectSQL, args...)
// log.Println(selectSQL + ` limit 1 for update`)
row := tx.QueryRow(selectSQL+` limit 1 for update`, args...)
defer func() {
err := tx.Commit()

View File

@ -2,6 +2,8 @@ package intimate
import (
"testing"
"github.com/tidwall/gjson"
)
func TestStoreInsert(t *testing.T) {
@ -25,5 +27,19 @@ func TestStoreInsertCase1(t *testing.T) {
func TestStorePopCase1(t *testing.T) {
store := NewStore("source_openrec")
t.Error(store.Pop("openrec_ranking"))
source, err := store.Pop("openrec_ranking")
if err != nil {
t.Error(err)
}
t.Error(source.GetOperator())
t.Error(gjson.Valid(source.GetSource().String))
result := gjson.Parse(source.GetSource().String)
if result.IsArray() {
for _, User := range result.Array() {
t.Error(User.Get("channel.id").String())
}
} else {
t.Error("array error")
}
}

View File

@ -1 +0,0 @@
openrec

View File

@ -1 +0,0 @@
../../config.yaml

View File

@ -0,0 +1 @@
task1

View File

@ -0,0 +1 @@
../../../config.yaml

View File

@ -0,0 +1 @@
task2

View File

@ -0,0 +1,2 @@
database:
uri: "root:@tcp(127.0.0.1:4000)/intimate_source"

View File

@ -0,0 +1,8 @@
package main
import "github.com/474420502/hunter"
func main() {
ht := hunter.NewHunter(oer)
ht.Execute()
}

View File

@ -0,0 +1,61 @@
package main
import (
"intimate"
"log"
"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) {
source, err := store.Pop(targetTypeRanking)
if err != nil {
log.Println(err)
return
}
if source != nil {
result := gjson.Parse(source.GetSource().String)
if result.IsArray() {
for _, User := range result.Array() {
userid := User.Get("channel.id").String()
openrecUser := &OpenrecUser{}
openrecUser.PreGetUrl = hunter.PreGetUrl("https://www.openrec.tv/user/" + userid + "/supporters")
cxt.AddParentTask(openrecUser)
}
} else {
log.Println("array error:", result.Str)
}
}
}
// OpenrecUser 获取用户信息
type OpenrecUser struct {
hunter.PreGetUrl
}
// Execute 执行方法
func (oer *OpenrecUser) Execute(cxt *hunter.TaskContext) {
}

View File

@ -0,0 +1,12 @@
package main
import (
"testing"
"github.com/474420502/hunter"
)
func TestOpenrecUser(t *testing.T) {
ht := hunter.NewHunter(oer)
ht.Execute()
}