TODO: nextTime
This commit is contained in:
parent
1e7a3cdab3
commit
fdd9fb0bf3
105
task.go
105
task.go
|
@ -1,24 +1,29 @@
|
|||
package imitate
|
||||
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"474420502.top/eson/crontabex"
|
||||
|
||||
crontab "474420502.top/eson/crontabex"
|
||||
"474420502.top/eson/curl2info"
|
||||
"474420502.top/eson/requests"
|
||||
)
|
||||
|
||||
var register map[string]reflect.Type
|
||||
var register = make(map[string]reflect.Type)
|
||||
|
||||
func init() {
|
||||
|
||||
}
|
||||
|
||||
// Register 注册 类型 ITask为样本的类型
|
||||
func Register(name string, itype interface{}) {
|
||||
register[name] = reflect.TypeOf(itype)
|
||||
}
|
||||
|
||||
func makeRegisterType(name string) reflect.Type {
|
||||
return reflect.New(register[name]).Type().Elem()
|
||||
func makeRegisterType(name string) interface{} {
|
||||
result := reflect.New(register[name]).Interface()
|
||||
return result
|
||||
}
|
||||
|
||||
// Person 以人为单位
|
||||
|
@ -60,17 +65,21 @@ func splitTasks(conf *Config) []ITask {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
task := makeRegisterType(curl.ITask).Elem().(ITask)
|
||||
if curl.Crontab != "" {
|
||||
task.SetCrontab(curl.Crontab)
|
||||
} else {
|
||||
task.SetCrontab(conf.Crontab)
|
||||
}
|
||||
task := makeRegisterType(curl.ITask).(ITask)
|
||||
|
||||
switch conf.Mode {
|
||||
case 0:
|
||||
copy(task.GetProxies(), conf.Proxies)
|
||||
|
||||
if curl.Crontab != "" {
|
||||
task.SetCrontab(curl.Crontab)
|
||||
} else {
|
||||
log.Println(conf.Crontab)
|
||||
task.SetCrontab(conf.Crontab)
|
||||
}
|
||||
task.SetCurl(curl)
|
||||
task.AppendProxies(conf.Proxies...)
|
||||
tasks = append(tasks, task)
|
||||
|
||||
case 1:
|
||||
for _, proxy := range conf.Proxies {
|
||||
ncurl, err := curl2info.ParseRawCURL(scurl)
|
||||
|
@ -78,12 +87,13 @@ func splitTasks(conf *Config) []ITask {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
ptask := makeRegisterType(ncurl.ITask).Elem().(ITask)
|
||||
if curl.Crontab != "" {
|
||||
ptask.SetCrontab(curl.Crontab)
|
||||
ptask := makeRegisterType(ncurl.ITask).(ITask)
|
||||
if ncurl.Crontab != "" {
|
||||
ptask.SetCrontab(ncurl.Crontab)
|
||||
} else {
|
||||
ptask.SetCrontab(conf.Crontab)
|
||||
}
|
||||
InitTask(ptask, ncurl)
|
||||
|
||||
ptask.AppendProxies(proxy)
|
||||
tasks = append(tasks, task)
|
||||
|
@ -95,9 +105,9 @@ func splitTasks(conf *Config) []ITask {
|
|||
|
||||
// Execute 人的执行所有任务
|
||||
func (person *Person) Execute() {
|
||||
// for _, task := range person.Tasks {
|
||||
// // ExecuteOnPlan(task)
|
||||
// }
|
||||
for _, task := range person.Tasks {
|
||||
ExecuteOnPlan(task)
|
||||
}
|
||||
}
|
||||
|
||||
// ITask 继承这个接口的类
|
||||
|
@ -148,39 +158,36 @@ func (task *Task) SetCrontab(cron string) {
|
|||
task.crontab = crontab.NewCrontab(cron)
|
||||
}
|
||||
|
||||
//
|
||||
// func (task *Task) AppendPlans(plans ...IExecute) {
|
||||
// if len(plans) != 0 {
|
||||
// for _, plan := range plans {
|
||||
// task.plans = append(task.plans, plan)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
func (task *Task) TimeUp() bool {
|
||||
return task.crontab.TimeUp()
|
||||
}
|
||||
|
||||
// func (task *Task) GetPlans() []IExecute {
|
||||
// return task.plans
|
||||
// }
|
||||
func (task *Task) NextTime() time.Time {
|
||||
return task.crontab.NextTime()
|
||||
}
|
||||
|
||||
// // InitTask 生成一个新任务
|
||||
// func InitTask(task ITask, Curl *curl2info.CURL) {
|
||||
// InitTask 生成一个新任务
|
||||
func InitTask(task ITask, Curl *curl2info.CURL) {
|
||||
task.SetCurl(Curl)
|
||||
}
|
||||
|
||||
// // task.Conf = NewConfig(conf)
|
||||
// task.SetCurl(Curl)
|
||||
// task.AppendPlans(Plans...)
|
||||
// }
|
||||
// ExecuteOnPlan 按照计划执行任务并返回结果
|
||||
func ExecuteOnPlan(task ITask) {
|
||||
log.Println(task)
|
||||
for i := 0; i < 2; i++ {
|
||||
|
||||
// // ExecuteOnPlan 按照计划执行任务并返回结果
|
||||
// func ExecuteOnPlan(task ITask) {
|
||||
// for _, exec := range task.GetPlans() {
|
||||
// if exec.TimeTo() >= 0 {
|
||||
// task.Execute() // 事件 在这里变化
|
||||
// exec.CalculateTrigger()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if task.TimeUp() {
|
||||
task.Execute() // 事件 在这里变化
|
||||
}
|
||||
|
||||
// Execute 根据curl信息执行, TODO: 通用方法设置, 多太实现
|
||||
// func (task *Task) Execute() {
|
||||
// resp, err := task.Curl.CreateWorkflow(nil).Execute()
|
||||
// log.Println(resp, err)
|
||||
// }
|
||||
nextTime := task.NextTime()
|
||||
log.Println(nextTime)
|
||||
time.Sleep(time.Second * 2)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Request 根据curl信息执行, TODO: 通用方法设置, 多太实现
|
||||
func (task *Task) Request() (*requests.Response, error) {
|
||||
return task.curl.CreateWorkflow(nil).Execute()
|
||||
}
|
||||
|
|
14
task_test.go
14
task_test.go
|
@ -2,8 +2,8 @@ package imitate
|
|||
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"474420502.top/eson/curl2info"
|
||||
)
|
||||
|
@ -29,14 +29,20 @@ type Toutiao struct {
|
|||
}
|
||||
|
||||
func (tt *Toutiao) Execute() {
|
||||
|
||||
resp, err := tt.Request()
|
||||
log.Println(resp, err)
|
||||
}
|
||||
|
||||
func TestExecutePlan(t *testing.T) {
|
||||
// person := NewPerson("test.yaml")
|
||||
|
||||
time.Sleep(time.Second * 2)
|
||||
Register("toutiao", Toutiao{})
|
||||
|
||||
person := NewPerson()
|
||||
person.LoadConfig("test.yaml")
|
||||
log.Println(person.Tasks, reflect.TypeOf(person.Tasks[0]), person.Tasks[0].GetCurl())
|
||||
person.Execute()
|
||||
|
||||
t.Error("")
|
||||
// for _, task := range person.Tasks.GetLoopValues() {
|
||||
// task.GetValue().(*Task).ExecuteOnPlan()
|
||||
// }
|
||||
|
|
|
@ -1 +1 @@
|
|||
curl 'http://is.snssdk.com/2/article/information/v24/?latitude=22.831367&longitude=113.511515&group_id=6565653745026204168&item_id=6565653745026204168&aggr_type=1&context=1&from_category=news_game&article_page=0&iid=34903754482&device_id=41148471494&ac=wifi&channel=oppo-cpa&aid=13&app_name=news_article&version_code=676&version_name=6.7.6&device_platform=android&ab_version=304489%2C261579%2C373245%2C360501%2C374617%2C366851%2C356335%2C345191%2C271178%2C357704%2C326524%2C326532%2C292723%2C366036%2C323233%2C371779%2C346557%2C351090%2C319958%2C372620%2C362184%2C214069%2C31643%2C333971%2C366873%2C374962%2C372618%2C280449%2C281298%2C366489%2C325619%2C373770%2C357402%2C361073%2C362402%2C290191%2C370014%2C353484%2C375739%2C373725%2C295827%2C353305%2C375426%2C374426%2C239095%2C360541%2C344347%2C170988%2C371590%2C368831%2C368827%2C368775%2C374117%2C365053%2C374232%2C368303%2C375692%2C330632%2C297059%2C374250%2C276206%2C286212%2C350193%2C365036%2C373741%2C374405%2C373368%2C370846%2C364453%2C375713%2C369501%2C369165%2C368839%2C375433%2C373123%2C371555%2C371963%2C374142%2C372907&ab_client=a1%2Cc4%2Ce1%2Cf1%2Cg2%2Cf7&ab_group=94567%2C102754%2C181430&ab_feature=94567%2C102754&abflag=3&ssmix=a&device_type=ONEPLUS+A3010&device_brand=OnePlus&language=zh&os_api=26&os_version=8.0.0&uuid=864854034514328&openudid=9b35a4035eecee2c&manifest_version_code=676&resolution=1080*1920&dpi=420&update_version_code=67610&_rticket=1528706910264&plugin=10603&pos=5r_-9Onkv6e_eCQieCoDeCUfv7G_8fLz-vTp6Pn4v6esrK6zqKysqKyosb_x_On06ej5-L-nr6-zpa6srquqsb_88Pzt3vTp5L-nv3gkIngqA3glH7-xv_zw_O3R8vP69Ono-fi_p6ysrrOupauqqaSxv_zw_O3R_On06ej5-L-nr66zrairpKqv4A%3D%3D&fp=HrT_FlD_PMcIFlD5FSU1FYmeFrxO&rom_version=26&ts=1528706911&as=a265e371dff53b57de5999&mas=0073e8ef3f9a8b842da0ead7d35c0597ea2ee0ccce5e5d5db5' -H 'Accept-Encoding: gzip' -H 'X-SS-REQ-TICKET: 1528706910267' -H 'User-Agent: Dalvik/2.1.0 (Linux; U; Android 8.0.0; ONEPLUS A3010 Build/OPR1.170623.032) NewsArticle/6.7.6 okhttp/3.10.0.1' -H 'Cookie: odin_tt=210899a257b5fe787a3465e2220fb94d91d5ad34c77dee3560f93fccc82dd738cccb301770f633530fdd6ceea955983d; UM_distinctid=163ace3b0050-08fccf530af621-f1c0e26-49a10-163ace3b0093e8; CNZZDATA1271720685=1435124261-1527612007-%7C1527612007; CNZZDATA1264530760=119491224-1527609979-%7C1527612115; JSESSIONID=67814B7DDE08D5A9F3B3D684220CF3FB; alert_coverage=6; qh[360]=1; install_id=34903754482; ttreq=1$b7221ef01bd5ed7c030f5db45e959686c9ddd0d2' -H 'Host: is.snssdk.com' -H 'Connection: Keep-Alive'
|
||||
curl 'http://is.snssdk.com/2/article/information/v24/?latitude=22.831367&longitude=113.511515&group_id=6565653745026204168&item_id=6565653745026204168&aggr_type=1&context=1&from_category=news_game&article_page=0&iid=34903754482&device_id=41148471494&ac=wifi&channel=oppo-cpa&aid=13&app_name=news_article&version_code=676&version_name=6.7.6&device_platform=android&ab_version=304489%2C261579%2C373245%2C360501%2C374617%2C366851%2C356335%2C345191%2C271178%2C357704%2C326524%2C326532%2C292723%2C366036%2C323233%2C371779%2C346557%2C351090%2C319958%2C372620%2C362184%2C214069%2C31643%2C333971%2C366873%2C374962%2C372618%2C280449%2C281298%2C366489%2C325619%2C373770%2C357402%2C361073%2C362402%2C290191%2C370014%2C353484%2C375739%2C373725%2C295827%2C353305%2C375426%2C374426%2C239095%2C360541%2C344347%2C170988%2C371590%2C368831%2C368827%2C368775%2C374117%2C365053%2C374232%2C368303%2C375692%2C330632%2C297059%2C374250%2C276206%2C286212%2C350193%2C365036%2C373741%2C374405%2C373368%2C370846%2C364453%2C375713%2C369501%2C369165%2C368839%2C375433%2C373123%2C371555%2C371963%2C374142%2C372907&ab_client=a1%2Cc4%2Ce1%2Cf1%2Cg2%2Cf7&ab_group=94567%2C102754%2C181430&ab_feature=94567%2C102754&abflag=3&ssmix=a&device_type=ONEPLUS+A3010&device_brand=OnePlus&language=zh&os_api=26&os_version=8.0.0&uuid=864854034514328&openudid=9b35a4035eecee2c&manifest_version_code=676&resolution=1080*1920&dpi=420&update_version_code=67610&_rticket=1528706910264&plugin=10603&pos=5r_-9Onkv6e_eCQieCoDeCUfv7G_8fLz-vTp6Pn4v6esrK6zqKysqKyosb_x_On06ej5-L-nr6-zpa6srquqsb_88Pzt3vTp5L-nv3gkIngqA3glH7-xv_zw_O3R8vP69Ono-fi_p6ysrrOupauqqaSxv_zw_O3R_On06ej5-L-nr66zrairpKqv4A%3D%3D&fp=HrT_FlD_PMcIFlD5FSU1FYmeFrxO&rom_version=26&ts=1528706911&as=a265e371dff53b57de5999&mas=0073e8ef3f9a8b842da0ead7d35c0597ea2ee0ccce5e5d5db5' --task toutiao -H 'Accept-Encoding: gzip' -H 'X-SS-REQ-TICKET: 1528706910267' -H 'User-Agent: Dalvik/2.1.0 (Linux; U; Android 8.0.0; ONEPLUS A3010 Build/OPR1.170623.032) NewsArticle/6.7.6 okhttp/3.10.0.1' -H 'Cookie: odin_tt=210899a257b5fe787a3465e2220fb94d91d5ad34c77dee3560f93fccc82dd738cccb301770f633530fdd6ceea955983d; UM_distinctid=163ace3b0050-08fccf530af621-f1c0e26-49a10-163ace3b0093e8; CNZZDATA1271720685=1435124261-1527612007-%7C1527612007; CNZZDATA1264530760=119491224-1527609979-%7C1527612115; JSESSIONID=67814B7DDE08D5A9F3B3D684220CF3FB; alert_coverage=6; qh[360]=1; install_id=34903754482; ttreq=1$b7221ef01bd5ed7c030f5db45e959686c9ddd0d2' -H 'Host: is.snssdk.com' -H 'Connection: Keep-Alive'
|
|
@ -7,7 +7,7 @@ timeout: 12
|
|||
priority : 10000
|
||||
|
||||
# curls: "@test.curl" // 支持, 列表 与 单项字符串
|
||||
curls : ["@test.curl", "curl 'https://segmentfault.com/a/1190000004850183' -H 'authority: segmentfault.com' -H 'cache-control: max-age=0' -H 'upgrade-insecure-requests: 1' -H 'user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: zh' -H 'cookie: _ga=GA1.2.923011700.1533555581; PHPSESSID=web1~3uf1ijg2h8nctqdof7aa27g1p8; Hm_lvt_e23800c454aa573c0ccb16b52665ac26=1542945905,1542945911,1542967158,1542969075; Hm_lpvt_e23800c454aa573c0ccb16b52665ac26=1542969075' --compressed"]
|
||||
curls : "@test.curl"
|
||||
# next_do : "doothers"
|
||||
|
||||
device : "eson-OnePlus"
|
||||
|
|
Loading…
Reference in New Issue
Block a user