diff --git a/main.go b/main.go index 6fd4766..5ca58f3 100644 --- a/main.go +++ b/main.go @@ -3,14 +3,11 @@ package main // InitConfig 初始化配置加载 config.yaml(yml) var InitConfig *Config -// SourceStore 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql -var SourceStore *Store - func init() { InitConfig = &Config{} InitConfig.Load() - SourceStore = NewStore() + storeOpenrec = NewStore() } func main() { diff --git a/platform_openrec.go b/platform_openrec.go index 69fac89..a4b95c0 100644 --- a/platform_openrec.go +++ b/platform_openrec.go @@ -7,6 +7,28 @@ import ( "github.com/474420502/hunter" ) +var openrecRanking *OpenrecRanking + +// storeOpenrec 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql +var storeOpenrec *Store + +func init() { + + openrecRanking = &OpenrecRanking{} + openrecRanking.PreCurlUrl = `curl 'https://public.openrec.tv/external/api/v5/channel-ranks?period=monthly&date=&tag=&page=1' \ + -H 'authority: public.openrec.tv' \ + -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 'origin: https://www.openrec.tv' \ + -H 'sec-fetch-site: same-site' \ + -H 'sec-fetch-mode: cors' \ + -H 'sec-fetch-dest: empty' \ + -H 'referer: https://www.openrec.tv/ranking' \ + -H 'accept-language: zh-CN,zh;q=0.9' \ + -H 'if-none-match: W/"25edb-aUYBdmLqZcr6DW4ZWKX9r2aqolg"' \ + --compressed` +} + /* CREATE TABLE `platform_openrec` ( `url` text NOT NULL, diff --git a/platform_openrec_test.go b/platform_openrec_test.go index 9296a5b..71371cd 100644 --- a/platform_openrec_test.go +++ b/platform_openrec_test.go @@ -32,20 +32,20 @@ func (or *OpenrecRankingTest) Execute(cxt *hunter.TaskContext) { } func TestRanking(t *testing.T) { - curlBash := `curl 'https://public.openrec.tv/external/api/v5/channel-ranks?period=monthly&date=&tag=&page=1' \ - -H 'authority: public.openrec.tv' \ - -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 'origin: https://www.openrec.tv' \ - -H 'sec-fetch-site: same-site' \ - -H 'sec-fetch-mode: cors' \ - -H 'sec-fetch-dest: empty' \ - -H 'referer: https://www.openrec.tv/ranking' \ - -H 'accept-language: zh-CN,zh;q=0.9' \ - -H 'if-none-match: W/"25edb-aUYBdmLqZcr6DW4ZWKX9r2aqolg"' \ - --compressed` + // curlBash := `curl 'https://public.openrec.tv/external/api/v5/channel-ranks?period=monthly&date=&tag=&page=1' \ + // -H 'authority: public.openrec.tv' \ + // -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 'origin: https://www.openrec.tv' \ + // -H 'sec-fetch-site: same-site' \ + // -H 'sec-fetch-mode: cors' \ + // -H 'sec-fetch-dest: empty' \ + // -H 'referer: https://www.openrec.tv/ranking' \ + // -H 'accept-language: zh-CN,zh;q=0.9' \ + // -H 'if-none-match: W/"25edb-aUYBdmLqZcr6DW4ZWKX9r2aqolg"' \ + // --compressed` - ht := hunter.NewHunter(&OpenrecRankingTest{hunter.PreCurlUrl(curlBash)}) + ht := hunter.NewHunter(openrecRanking) ht.SetShare("test", t) ht.Execute() } diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e91518a --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# 数据监控系统 + +1. 初版. \ No newline at end of file diff --git a/store.go b/store.go index c437dac..47f8f2a 100644 --- a/store.go +++ b/store.go @@ -2,6 +2,7 @@ package main import ( "database/sql" + "log" "time" _ "github.com/go-sql-driver/mysql" @@ -32,5 +33,8 @@ func NewStore() *Store { // Save 储存数据 func (store *Store) Save(isource ISource) { - store.db.Exec("insert into `platform_openrec`(url, target_type, source, ext) values(?,?,?,?)", isource.GetUrl(), isource.GetTargetType(), isource.GetSource(), isource.GetExt()) + _, err := store.db.Exec("insert into `platform_openrec`(url, target_type, source, ext) values(?,?,?,?)", isource.GetUrl(), isource.GetTargetType(), isource.GetSource(), isource.GetExt()) + if err != nil { + log.Println(err) + } }