diff --git a/.gitignore b/.gitignore index c0f6853..1920979 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ screenlog.* *.7z intimate *.gz + + diff --git a/config.go b/config.go index 15f5825..4b6ddb1 100644 --- a/config.go +++ b/config.go @@ -1,4 +1,4 @@ -package main +package intimate import ( "errors" @@ -8,6 +8,15 @@ import ( "gopkg.in/yaml.v2" ) +// InitConfig 初始化配置加载 config.yaml(yml) +var InitConfig *Config + +func init() { + InitConfig = &Config{} + InitConfig.Load() + // storeOpenrec = NewStore() +} + // Config 配置 type Config struct { Database struct { diff --git a/config_test.go b/config_test.go index d28859e..aaffef3 100644 --- a/config_test.go +++ b/config_test.go @@ -1,4 +1,4 @@ -package main +package intimate import "testing" diff --git a/go.sum b/go.sum index 1341f5c..9a57a03 100644 --- a/go.sum +++ b/go.sum @@ -143,6 +143,7 @@ google.golang.org/genproto v0.0.0-20190626174449-989357319d63/go.mod h1:z3L6/3dT google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go deleted file mode 100644 index 5ca58f3..0000000 --- a/main.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -// InitConfig 初始化配置加载 config.yaml(yml) -var InitConfig *Config - -func init() { - InitConfig = &Config{} - InitConfig.Load() - - storeOpenrec = NewStore() -} - -func main() { - -} diff --git a/store.go b/store.go index dcec84c..90a0323 100644 --- a/store.go +++ b/store.go @@ -1,4 +1,4 @@ -package main +package intimate import ( "database/sql" diff --git a/store_test.go b/store_test.go index cc68934..7889937 100644 --- a/store_test.go +++ b/store_test.go @@ -1,4 +1,4 @@ -package main +package intimate import ( "testing" diff --git a/tasks/openrec/.gitignore b/tasks/openrec/.gitignore new file mode 100644 index 0000000..48a81b6 --- /dev/null +++ b/tasks/openrec/.gitignore @@ -0,0 +1 @@ +openrec \ No newline at end of file diff --git a/tasks/openrec/config.yaml b/tasks/openrec/config.yaml new file mode 120000 index 0000000..82800a0 --- /dev/null +++ b/tasks/openrec/config.yaml @@ -0,0 +1 @@ +../../config.yaml \ No newline at end of file diff --git a/tasks/openrec/main.go b/tasks/openrec/main.go new file mode 100644 index 0000000..a8f96c1 --- /dev/null +++ b/tasks/openrec/main.go @@ -0,0 +1,8 @@ +package main + +import "github.com/474420502/hunter" + +func main() { + ht := hunter.NewHunter(openrecRanking) + ht.Execute() +} diff --git a/source_openrec.go b/tasks/openrec/source_openrec.go similarity index 94% rename from source_openrec.go rename to tasks/openrec/source_openrec.go index 771e90a..897db8b 100644 --- a/source_openrec.go +++ b/tasks/openrec/source_openrec.go @@ -6,14 +6,16 @@ import ( "strconv" "time" + "intimate" + "github.com/474420502/hunter" ) var targetTypeRanking = "openrec_ranking" var openrecRanking *OpenrecRanking -// storeOpenrec 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql -var storeOpenrec *Store +// store 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql +var store *intimate.Store = intimate.NewStore() func init() { @@ -30,6 +32,7 @@ func init() { -H 'accept-language: zh-CN,zh;q=0.9' \ -H 'if-none-match: W/"25edb-aUYBdmLqZcr6DW4ZWKX9r2aqolg"' \ --compressed` + } /* @@ -162,8 +165,7 @@ func (or *OpenrecRanking) Execute(cxt *hunter.TaskContext) { data := &SourceOpenrec{} content := resp.Content() - log.Println(len(content)) - if len(content) <= 300 { + if len(content) <= 200 { return } @@ -180,7 +182,7 @@ func (or *OpenrecRanking) Execute(cxt *hunter.TaskContext) { data.SetErrorMsg(errorMsg) data.SetOperator(10000) - storeOpenrec.Save(data) + store.Save(data) return } @@ -189,7 +191,7 @@ func (or *OpenrecRanking) Execute(cxt *hunter.TaskContext) { wf.SetQuery(querys) data.SetErrorMsg(errorMsg) - storeOpenrec.Save(data) + store.Save(data) time.Sleep(time.Second * 2) } diff --git a/source_openrec_test.go b/tasks/openrec/source_openrec_test.go similarity index 94% rename from source_openrec_test.go rename to tasks/openrec/source_openrec_test.go index 6ef3628..8eddfd6 100644 --- a/source_openrec_test.go +++ b/tasks/openrec/source_openrec_test.go @@ -55,3 +55,8 @@ func TestRanking(t *testing.T) { ht.SetShare("test", t) ht.Execute() } + +func TestRankingInsert(t *testing.T) { + ht := hunter.NewHunter(openrecRanking) + ht.Execute() +}