TODO: openrec user data. isource update interface
This commit is contained in:
parent
5cbb17d6d4
commit
0a2a134511
4
store.go
4
store.go
|
@ -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()
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
1
tasks/openrec/.gitignore
vendored
1
tasks/openrec/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
openrec
|
|
@ -1 +0,0 @@
|
|||
../../config.yaml
|
1
tasks/openrec/openrec_task1/.gitignore
vendored
Normal file
1
tasks/openrec/openrec_task1/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
task1
|
1
tasks/openrec/openrec_task1/config.yaml
Symbolic link
1
tasks/openrec/openrec_task1/config.yaml
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../../config.yaml
|
1
tasks/openrec/openrec_task2/.gitignore
vendored
Normal file
1
tasks/openrec/openrec_task2/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
task2
|
2
tasks/openrec/openrec_task2/config.yaml
Normal file
2
tasks/openrec/openrec_task2/config.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
database:
|
||||
uri: "root:@tcp(127.0.0.1:4000)/intimate_source"
|
8
tasks/openrec/openrec_task2/main.go
Normal file
8
tasks/openrec/openrec_task2/main.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
import "github.com/474420502/hunter"
|
||||
|
||||
func main() {
|
||||
ht := hunter.NewHunter(oer)
|
||||
ht.Execute()
|
||||
}
|
61
tasks/openrec/openrec_task2/task_openrec.go
Normal file
61
tasks/openrec/openrec_task2/task_openrec.go
Normal 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) {
|
||||
|
||||
}
|
12
tasks/openrec/openrec_task2/task_openrec_test.go
Normal file
12
tasks/openrec/openrec_task2/task_openrec_test.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/474420502/hunter"
|
||||
)
|
||||
|
||||
func TestOpenrecUser(t *testing.T) {
|
||||
ht := hunter.NewHunter(oer)
|
||||
ht.Execute()
|
||||
}
|
Loading…
Reference in New Issue
Block a user