diff --git a/store.go b/store.go index 93a9d36..505b1f5 100644 --- a/store.go +++ b/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() diff --git a/store_test.go b/store_test.go index c19bcd7..5ec7e00 100644 --- a/store_test.go +++ b/store_test.go @@ -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") + } + } diff --git a/tasks/openrec/.gitignore b/tasks/openrec/.gitignore deleted file mode 100644 index 48a81b6..0000000 --- a/tasks/openrec/.gitignore +++ /dev/null @@ -1 +0,0 @@ -openrec \ No newline at end of file diff --git a/tasks/openrec/config.yaml b/tasks/openrec/config.yaml deleted file mode 120000 index 82800a0..0000000 --- a/tasks/openrec/config.yaml +++ /dev/null @@ -1 +0,0 @@ -../../config.yaml \ No newline at end of file diff --git a/tasks/openrec/openrec_task1/.gitignore b/tasks/openrec/openrec_task1/.gitignore new file mode 100644 index 0000000..8117159 --- /dev/null +++ b/tasks/openrec/openrec_task1/.gitignore @@ -0,0 +1 @@ +task1 \ No newline at end of file diff --git a/tasks/openrec/openrec_task1/config.yaml b/tasks/openrec/openrec_task1/config.yaml new file mode 120000 index 0000000..e416226 --- /dev/null +++ b/tasks/openrec/openrec_task1/config.yaml @@ -0,0 +1 @@ +../../../config.yaml \ No newline at end of file diff --git a/tasks/openrec/main.go b/tasks/openrec/openrec_task1/main.go similarity index 100% rename from tasks/openrec/main.go rename to tasks/openrec/openrec_task1/main.go diff --git a/tasks/openrec/source_openrec.go b/tasks/openrec/openrec_task1/source_openrec.go similarity index 100% rename from tasks/openrec/source_openrec.go rename to tasks/openrec/openrec_task1/source_openrec.go diff --git a/tasks/openrec/source_openrec_test.go b/tasks/openrec/openrec_task1/source_openrec_test.go similarity index 100% rename from tasks/openrec/source_openrec_test.go rename to tasks/openrec/openrec_task1/source_openrec_test.go diff --git a/tasks/openrec/task_openrec.go b/tasks/openrec/openrec_task1/task_openrec.go similarity index 100% rename from tasks/openrec/task_openrec.go rename to tasks/openrec/openrec_task1/task_openrec.go diff --git a/tasks/openrec/openrec_task2/.gitignore b/tasks/openrec/openrec_task2/.gitignore new file mode 100644 index 0000000..7508886 --- /dev/null +++ b/tasks/openrec/openrec_task2/.gitignore @@ -0,0 +1 @@ +task2 \ No newline at end of file diff --git a/tasks/openrec/openrec_task2/config.yaml b/tasks/openrec/openrec_task2/config.yaml new file mode 100644 index 0000000..43d8752 --- /dev/null +++ b/tasks/openrec/openrec_task2/config.yaml @@ -0,0 +1,2 @@ +database: + uri: "root:@tcp(127.0.0.1:4000)/intimate_source" \ No newline at end of file diff --git a/tasks/openrec/openrec_task2/main.go b/tasks/openrec/openrec_task2/main.go new file mode 100644 index 0000000..4043048 --- /dev/null +++ b/tasks/openrec/openrec_task2/main.go @@ -0,0 +1,8 @@ +package main + +import "github.com/474420502/hunter" + +func main() { + ht := hunter.NewHunter(oer) + ht.Execute() +} diff --git a/tasks/openrec/openrec_task2/task_openrec.go b/tasks/openrec/openrec_task2/task_openrec.go new file mode 100644 index 0000000..59c279f --- /dev/null +++ b/tasks/openrec/openrec_task2/task_openrec.go @@ -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) { + +} diff --git a/tasks/openrec/openrec_task2/task_openrec_test.go b/tasks/openrec/openrec_task2/task_openrec_test.go new file mode 100644 index 0000000..d29684f --- /dev/null +++ b/tasks/openrec/openrec_task2/task_openrec_test.go @@ -0,0 +1,12 @@ +package main + +import ( + "testing" + + "github.com/474420502/hunter" +) + +func TestOpenrecUser(t *testing.T) { + ht := hunter.NewHunter(oer) + ht.Execute() +} diff --git a/testfile/test.json b/testfile/openrec_ranking.json similarity index 100% rename from testfile/test.json rename to testfile/openrec_ranking.json