forked from arcsun/neteaseMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
82 lines (69 loc) · 1.87 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#coding=utf-8
from flask import Flask, redirect
import webbrowser
import cPickle as pickle
from codepy import menulog
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Netease Menu!'
@app.route('/menu/<int:day>')
def menu(day= 0):
# 今天0, 明天1...
from codepy import menu
url = menu.Menu(day).process()
if url.startswith('http'):
return redirect(url)
else:
return url
@app.route('/menu/clear')
def clearMaybe():
# 清空maybe
try:
f = file('record.pkl', 'rb')
startId = pickle.load(f)
lastQuery = pickle.load(f)
cache = pickle.load(f)
maybe = pickle.load(f)
maybe = []
f.close()
f = file('record.pkl', 'wb')
pickle.dump(startId, f, 0)
pickle.dump(lastQuery, f, 0)
pickle.dump(cache, f, 0)
pickle.dump(maybe, f, 0)
f.close()
msg = u'清空maybe'
menulog.info(msg)
return msg
except (IOError, EOFError):
msg = u'缓存读取错误'
menulog.info(msg)
return msg
@app.route('/start/<int:startid>')
def start(startid= 15900):
# 重置起始查找点为指定值
try:
f = file('record.pkl', 'rb')
startId = pickle.load(f)
startId = startid
lastQuery = pickle.load(f)
cache = pickle.load(f)
maybe = pickle.load(f)
f.close()
f = file('record.pkl', 'wb')
pickle.dump(startId, f, 0)
pickle.dump(lastQuery, f, 0)
pickle.dump(cache, f, 0)
pickle.dump(maybe, f, 0)
f.close()
msg = u'设置查找起点ID为:%d'% startid
menulog.info(msg)
return msg
except (IOError, EOFError):
msg = u'缓存读取错误'
menulog.info(msg)
return msg
if __name__ == '__main__':
webbrowser.open('http://127.0.0.1/menu/0')
app.run(port= 80)