1
0
forked from x/icebergs

opt 12306

This commit is contained in:
shaoying 2020-01-06 15:33:25 +08:00
parent 087169acd1
commit 3ae2c76660
2 changed files with 59 additions and 139 deletions

View File

@ -469,6 +469,8 @@ var Index = &ice.Context{Name: "web", Help: "网页模块",
// 缓存数据 // 缓存数据
cache := "" cache := ""
switch arg[1] { switch arg[1] {
case "raw":
cache, arg = arg[1], arg[1:]
case "cache": case "cache":
cache, arg = arg[1], arg[1:] cache, arg = arg[1], arg[1:]
} }
@ -592,6 +594,10 @@ var Index = &ice.Context{Name: "web", Help: "网页模块",
} }
switch cache { switch cache {
case "raw":
if b, e := ioutil.ReadAll(res.Body); m.Assert(e) {
m.Echo(string(b))
}
case "cache": case "cache":
// 缓存结果 // 缓存结果
m.Optionv("response", res) m.Optionv("response", res)

View File

@ -7,161 +7,75 @@ import (
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"fmt" "fmt"
"os"
"path"
"strings" "strings"
"time" "time"
) )
var Index = &ice.Context{Name: "mall", Help: "团队模块", var Index = &ice.Context{Name: "mall", Help: "团队模块",
Caches: map[string]*ice.Cache{}, Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{}, Configs: map[string]*ice.Config{
"railway": {Name: "railway", Help: "12306", Value: kit.Data()},
},
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(ice.WEB_SPIDE, "add", "12306", "https://kyfw.12306.cn") m.Cmd(ice.CTX_CONFIG, "load", "mall.json")
if m.Cmd(ice.WEB_SPIDE, "add", "12306", "https://kyfw.12306.cn"); !m.Confs("railway", "meta.site") {
list := strings.Split(strings.TrimPrefix(m.Cmdx(ice.WEB_SPIDE, "12306", "raw", "GET", "/otn/resources/js/framework/station_name.js?station_version=1.9090"), "var statuion_names ='"), "|")
for i := 0; i < len(list)-5; i += 5 {
m.Conf("railway", kit.Keys("meta.site", list[i+1]), list[i+2])
}
}
}}, }},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(ice.CTX_CONFIG, "save", "mall.json", "web.mall.railway")
}}, }},
"_miss": {Name: "miss", Help: "任务", Meta: map[string]interface{}{ "railway": &ice.Command{Name: "railway", Help: "12306", List: kit.List(
"exports": []interface{}{"you", "name"}, kit.MDB_INPUT, "text", "name", "date", "value", "2020-01-22",
"detail": []interface{}{"启动", "停止"}, kit.MDB_INPUT, "text", "name", "from", "value", "北京",
}, List: []interface{}{ kit.MDB_INPUT, "text", "name", "to", "value", "曲阜",
map[string]interface{}{"type": "text", "value": "", "name": "name"}, kit.MDB_INPUT, "button", "name", "查询",
map[string]interface{}{"type": "text", "value": "", "name": "type"}, ),
map[string]interface{}{"type": "button", "value": "创建", "action": "auto"}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { date := time.Now().Add(time.Hour * 24).Format("2006-01-02")
if len(arg) > 1 { if len(arg) > 0 {
switch arg[1] { date, arg = arg[0], arg[1:]
case "启动": }
case "停止": from := "北京"
m.Cmd("web.space", arg[0], "exit", "1") if len(arg) > 0 {
from, arg = arg[0], arg[1:]
}
from_code := m.Conf("railway", kit.Keys("meta.site", from))
to := "曲阜"
if len(arg) > 0 {
to, arg = arg[0], arg[1:]
}
to_code := m.Conf("railway", kit.Keys("meta.site", to))
m.Echo("%s->%s %s\n", from, to, date)
if len(arg) > 0 {
m.Cmdy(ice.WEB_SPIDE, "12306", "raw", "GET", fmt.Sprintf("/otn/czxx/queryByTrainNo?train_no=%s&from_station_telecode=%s&to_station_telecode=%s&depart_date=%s",
arg[0], from_code, to_code, date))
return return
} }
}
if len(arg) > 0 { m.Cmd(ice.WEB_SPIDE, "12306", "GET", fmt.Sprintf("/otn/leftTicket/init?linktypeid=dc&fs=%s,%s&ts=%s,%s&date=%s&flag=N,N,Y",
if !strings.Contains(arg[0], "-") { from, from_code, to, to_code, date))
arg[0] = m.Time("20060102-") + arg[0] m.Cmd(ice.WEB_SPIDE, "12306", "GET", fmt.Sprintf("/otn/leftTicket/queryZ?leftTicketDTO.train_date=%s&leftTicketDTO.from_station=%s&leftTicketDTO.to_station=%s&purpose_codes=ADULT",
} date, from_code, to_code)).Table(func(index int, value map[string]string, head []string) {
kit.Fetch(kit.Value(kit.UnMarshal(value["data"]), "result"), func(index int, value string) {
p := path.Join(m.Conf("miss", "meta.path"), arg[0]) fields := strings.Split(value, "|")
if _, e := os.Stat(p); e != nil { m.Push("车次", fields[3])
os.MkdirAll(p, 0777) m.Push("出发", fields[8])
} m.Push("到站", fields[9])
m.Push("时长", fields[10])
if !m.Confs("web.space", "hash."+arg[0]) { m.Push("二等座", fields[30])
m.Option("cmd_dir", p) m.Push("一等座", fields[31])
m.Option("cmd_type", "daemon")
m.Cmd(m.Confv("miss", "meta.cmd"))
}
}
m.Cmdy("nfs.dir", m.Conf("miss", "meta.path"), "", "time name")
m.Table(func(index int, value map[string]string, head []string) {
m.Push("status", kit.Select("stop", "start", m.Confs("web.space", "hash."+value["name"])))
})
}},
"_task": {Name: "task", Help: "任务",
Meta: map[string]interface{}{
"remote": "true",
},
List: []interface{}{
map[string]interface{}{"type": "select", "value": "create", "values": "create action cancel finish"},
map[string]interface{}{"type": "text", "value": "", "name": "name"},
map[string]interface{}{"type": "text", "value": "", "name": "text"},
map[string]interface{}{"type": "button", "value": "创建"},
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
switch arg[0] {
case "create":
id := m.Grow("web.chat.group", []string{kit.MDB_HASH, m.Option("sess.river"), "task"}, map[string]interface{}{
"name": arg[1],
"text": kit.Select("", arg, 2),
"status": "准备",
"begin_time": m.Time(),
"close_time": m.Time("3h"),
}) })
m.Log("info", "create task %v", id)
m.Echo("%d", id)
case "action":
case "cancel":
}
}},
"_process": {Name: "process", Help: "任务进度", Meta: map[string]interface{}{
"remote": "true",
"detail": []string{"编辑", "准备", "开始", "取消", "完成"},
}, List: []interface{}{
map[string]interface{}{"type": "text", "value": "0", "name": "offend"},
map[string]interface{}{"type": "text", "value": "10", "name": "limit"},
map[string]interface{}{"type": "text", "value": "", "name": "match"},
map[string]interface{}{"type": "text", "value": "", "name": "value"},
map[string]interface{}{"type": "button", "value": "查看", "action": "auto"},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[1] {
case "modify":
prefix := []string{"mdb.update", "web.chat.group", "hash." + m.Option("sess.river") + ".task", arg[0], arg[2], arg[3]}
m.Cmd(prefix)
arg = arg[4:]
case "准备", "开始", "取消", "完成":
msg := m.Cmd("mdb.select", "web.chat.group", "hash."+m.Option("sess.river")+".task", arg[0])
if msg.Append("status") == arg[1] {
arg = arg[4:]
break
}
prefix := []string{"mdb.update", "web.chat.group", "hash." + m.Option("sess.river") + ".task", arg[0], "status", arg[1]}
status := map[string][]string{
"准备->开始": []string{"begin_time", m.Time(), "close_time", m.Time("3h")},
"准备->取消": []string{"begin_time", m.Time(), "close_time", m.Time()},
"准备->完成": []string{"begin_time", m.Time(), "close_time", m.Time()},
"开始->准备": []string{"begin_time", m.Time(), "close_time", m.Time("3h")},
"开始->取消": []string{"close_time", m.Time()},
"开始->完成": []string{"close_time", m.Time()},
}[msg.Append("status")+"->"+arg[1]]
suffix := []string{"extra.list.-2.time", m.Time(), "extra.list.-3.status", arg[1]}
if len(status) > 0 {
m.Cmd(prefix, status, suffix)
}
arg = arg[4:]
}
m.Cmdy("mdb.select", "web.chat.group", "hash."+m.Option("sess.river")+".task", "0",
kit.Select("0", arg, 0), kit.Select("10", arg, 1), kit.Select("", arg, 2), kit.Select("", arg, 3),
kit.Select("id status begin_time close_time name text", arg, 4))
}},
"12306": &ice.Command{Name: "12306", Help: "12306", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
date := time.Now().Add(time.Hour * 24).Format("2006-01-02")
if len(arg) > 0 {
date, arg = arg[0], arg[1:]
}
to := "QFK"
if len(arg) > 0 {
to, arg = arg[0], arg[1:]
}
from := "BJP"
if len(arg) > 0 {
from, arg = arg[0], arg[1:]
}
m.Echo("%s->%s %s\n", from, to, date)
m.Cmd(ice.WEB_SPIDE, "12306", "GET", fmt.Sprintf("/otn/leftTicket/init?linktypeid=dc&fs=北京,BJP&ts=曲阜,QFK&date=%s&flag=N,N,Y", date))
m.Cmd(ice.WEB_SPIDE, "12306", "GET", fmt.Sprintf("/otn/leftTicket/queryZ?leftTicketDTO.train_date=%s&leftTicketDTO.from_station=%s&leftTicketDTO.to_station=%s&purpose_codes=ADULT", date, from, to)).Table(func(index int, value map[string]string, head []string) {
kit.Fetch(kit.Value(kit.UnMarshal(value["data"]), "result"), func(index int, value string) {
fields := strings.Split(value, "|")
m.Info("once %d len(%d) %v", index, len(fields), fields)
m.Push("车次--", fields[3])
m.Push("出发----", fields[8])
m.Push("到站----", fields[9])
m.Push("时长----", fields[10])
m.Push("二等座", fields[30])
m.Push("一等座", fields[31])
}) })
}) }},
return
}},
}, },
} }