-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
86 lines (75 loc) · 2.33 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
83
84
85
86
#!/usr/bin/env python
# coding: utf-8
import time
from session import Session
from login import Login
from appointment import Appointment
from parseconf import ParseConf
import webbrowser
import sys
reload(sys)
sys.setdefaultencoding('utf8')
DATELINE_CN = {'0':'上午', '1':'中午', '2':'晚上'}
CONFIG = ParseConf()
def apdate(appointment, datepoint):
"""
预约日期
:param appointment: 预约session
:param datepoint 需要预约的时间点 [('2017-05-27', '0')]
"""
(postdata, schedule) = appointment.timetable()
print u'获取预约日期表...'
for k,(d,i) in enumerate(datepoint):
# 11点40更新第10天预约
if schedule.has_key(d) == False:
return False, None
selected = schedule[d][int(i)]
if selected['state'] == 'lijiyuyue':
# 可预约提示
print d + DATELINE_CN[i] + u' 可以预约'
appointment.appointment(postdata, selected['name'])
return True, (d, i)
else:
continue
return False, None
if __name__ == '__main__':
session = Session().session
login = Login(session)
login.get_captcha()
login.show_image(login.captcha_path)
captcha = raw_input(u'输入验证码:')
payload = {
'username': CONFIG.user_name,
'password': CONFIG.password,
'captcha': captcha
}
(loginStat, loginMsg) = login.login(payload)
if loginStat == True:
print u'登录成功'
appointment = Appointment(session)
appointment.login()
nowtime = time.time()
count = 1
aplogin = False
# 已经登录
# 590-600登录 已经登录 (r)
while True:
time.sleep(CONFIG.sleep)
print count
count = count + 1
try:
ok, ret = apdate(appointment, CONFIG.date_line)
except Exception as e:
print e
continue
if ok == True:
print ret[0] + DATELINE_CN[ret[1]] + u'预约成功'
break
left = (time.time() - nowtime) % 600
if left <= 590:
aplogin = False
elif aplogin == False and left > 590:
appointment.login()
aplogin = True
else:
print u'登录失败'