package main import ( "database/sql" "time" "github.com/474420502/hunter" ) var targetTypeRanking = "openrec_ranking" 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, `target_type` varchar(64) NOT NULL, `source` longtext DEFAULT NULL, `ext` json DEFAULT NULL, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `operator` tinyint NOT NULL, KEY `operator_idx` (`operator`), KEY `update_time_idx` (`update_time`), KEY `target_type_idx` (`target_type`) ); */ type PlatformOpenrec struct { Url string // TargetType string // Source sql.NullString // Ext interface{} // UpdateTime time.Time // Operator int32 // } // GetOperator Get return Operator int32 func (po *PlatformOpenrec) GetOperator() int32 { return po.Operator } // SetOperator Set Operator int32 func (po *PlatformOpenrec) SetOperator(Operator int32) { po.Operator = Operator } // GetUpdateTime Get return UpdateTime time.Time func (po *PlatformOpenrec) GetUpdateTime() time.Time { return po.UpdateTime } // SetUpdateTime Set UpdateTime time.Time func (po *PlatformOpenrec) SetUpdateTime(UpdateTime time.Time) { po.UpdateTime = UpdateTime } // GetExt Get return Ext interface{} func (po *PlatformOpenrec) GetExt() interface{} { return po.Ext } // SetExt Set Ext interface{} func (po *PlatformOpenrec) SetExt(Ext interface{}) { po.Ext = Ext } // GetSource Get return Source sql.NullString func (po *PlatformOpenrec) GetSource() sql.NullString { return po.Source } // SetSource Set Source sql.NullString func (po *PlatformOpenrec) SetSource(Source sql.NullString) { po.Source = Source } // GetTargetType Get return TargetType string func (po *PlatformOpenrec) GetTargetType() string { return po.TargetType } // SetTargetType Set TargetType string func (po *PlatformOpenrec) SetTargetType(TargetType string) { po.TargetType = TargetType } // GetUrl Get return Url string func (po *PlatformOpenrec) GetUrl() string { return po.Url } // SetUrl Set Url string func (po *PlatformOpenrec) SetUrl(Url string) { po.Url = Url } // OpenrecRanking 获取排名任务 type OpenrecRanking struct { hunter.PreCurlUrl } // Execute 执行方法 func (or *OpenrecRanking) Execute(cxt *hunter.TaskContext) { resp, err := cxt.Hunt() if err != nil { panic(err) } data := &PlatformOpenrec{} content := resp.Content() data.SetSource(sql.NullString{String: string(content), Valid: len(content) > 0}) data.SetUrl(cxt.Workflow().GetRawURL()) data.SetTargetType(targetTypeRanking) storeOpenrec.Save(data) }