-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUJN_Seat.py
More file actions
145 lines (132 loc) · 6.48 KB
/
Copy pathUJN_Seat.py
File metadata and controls
145 lines (132 loc) · 6.48 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding:utf-8 -*-
import requests
import re
import datetime
import time
from twilio.rest import Client
def login(S,cookies):
url = "http://seat.ujn.edu.cn/"
try:
r = S.post(url,cookies=cookies,timeout=10)
if "请输入学号" in r.content:
print "login status error"
except Exception as e:
print "login error"
#print r.content
def send_msg(msg):
#添加自己的twilio配置
account_sid = 'twilio_sid'
auth_token = 'twilio_token'
client = Client(account_sid, auth_token)
message = client.messages.create(
from_='+twilio_phone',
body=msg,
to='+86your_phone'
)
def send_msg_to_me(msg):
account_sid = 'twilio_sid'
auth_token = 'twilio_token'
client = Client(account_sid, auth_token)
message = client.messages.create(
from_='+twilio_phone',
body=msg,
to='+86your_phone'
)
def get_token(S,cookies):
url = "http://seat.ujn.edu.cn/map"
r = S.get(url,cookies=cookies,timeout=10).content
return re.findall(r'SYNCHRONIZER_TOKEN\" value=\"(.*?)\"',r)[0]
def order(S,day,cookies):
token = get_token(S,cookies)
burp0_url = "http://seat.ujn.edu.cn:80/selfRes"
headers = {"Cache-Control": "max-age=0", "Origin": "http://seat.ujn.edu.cn", "Upgrade-Insecure-Requests": "1", "Content-Type": "application/x-www-form-urlencoded", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", "Referer": "http://seat.ujn.edu.cn/map", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "close"}
data={"SYNCHRONIZER_TOKEN": token, "SYNCHRONIZER_URI": "/map", "date": day, "seat": "40052", "start": "480", "end": "1320", "authid": "-1"}#座位参数,在网页可以看到
r=S.post(burp0_url, headers=headers, cookies=cookies, data=data,timeout=10)
returndata = r.content
#print returndata
tmrday = datetime.date.today() + datetime.timedelta(days=1)
if "系统已经为您预定好了" in returndata:
print "order success"
send_msg("已经为XXX成功预定了【{} 8:00-22:00】的专属座位,今天也要加油呀!😆".format(tmrday.strftime('%Y-%m-%d')))
send_msg_to_me("已经为XXX成功预定了【{} 8:00-22:00】的专属座位,今天也要加油呀!😆".format(tmrday.strftime('%Y-%m-%d')))
return "success"
elif "已有1个有效预约" in returndata:
print "one successed"
#send_msg("An existing appointment")
return "ordered"
elif "参数错误" in returndata:
print "error parameter,pls check order day"
return "error"
else:
return "none"
def order_tue(S,day,cookies):
token = get_token(S,cookies)
burp0_url = "http://seat.ujn.edu.cn:80/selfRes"
headers = {"Cache-Control": "max-age=0", "Origin": "http://seat.ujn.edu.cn", "Upgrade-Insecure-Requests": "1", "Content-Type": "application/x-www-form-urlencoded", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", "Referer": "http://seat.ujn.edu.cn/map", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "close"}
data={"SYNCHRONIZER_TOKEN": token, "SYNCHRONIZER_URI": "/map", "date": day, "seat": "40052", "start": "960", "end": "1320", "authid": "-1"}
r=S.post(burp0_url, headers=headers, cookies=cookies, data=data,timeout=10)
returndata = r.content
#print returndata
tmrday = datetime.date.today() + datetime.timedelta(days=1)
if "系统已经为您预定好了" in returndata:
print "order success"
send_msg("已经为XXX成功预定了【{} 16:00-22:00】的专属座位,今天也要加油呀!😆".format(tmrday.strftime('%Y-%m-%d')))
send_msg_to_me("已经为XXX成功预定了【{} 16:00-22:00】的专属座位,今天也要加油呀!😆".format(tmrday.strftime('%Y-%m-%d')))
return "success"
elif "已有1个有效预约" in returndata:
print "one successed"
#send_msg("An existing appointment")
return "ordered"
elif "参数错误" in returndata:
print "error parameter,pls check order day"
return "error"
else:
return "none"
def get_time():
dt1 = datetime.date.today() + datetime.timedelta(days=1)
dt2 = datetime.date.today() + datetime.timedelta(days=2)
tmr = dt1.strftime('%Y-%m-%d')
aftertmr = dt2.strftime('%Y-%m-%d')
return tmr,aftertmr
if __name__ == "__main__":
while True:
nowhour = datetime.datetime.now().strftime('%H')
nowmins = datetime.datetime.now().strftime('%M')
cookies = dict(JSESSIONID='XXXX')#用自己的cookie
S=requests.Session()
if int(nowhour) < 7 or int(nowhour) >= 22:
if int(nowhour) == 6 and int(nowmins) >= 50:
if int(nowmins) >= 56:
stime = 10
else:
stime = 60
else:
login(S,cookies)
print "order system is closing"
stime = 600
elif int(nowhour) < 8: #8点前自动预约
login(S,cookies)
day1,day2 = get_time()
if datetime.datetime.now().strftime('%a') == "Mon": #周一预约周二的
try:
status = order_tue(S,day1,cookies)
#print status
except:
status = "error"
else:
try:
status = order(S,day1,cookies)
except:
status = "error"
#order(S,day2,cookies)
if int(nowmins) <= 30 and status != "success":
stime = 5
else:
stime = 300
else:
login(S,cookies)
print "9:00 - 22:00 stop order"
stime = 600
nowtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
print "+++ Now Time +++ " + "|============" + nowtime + "============|"
time.sleep(stime)