-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
90 lines (73 loc) · 2.62 KB
/
main.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
87
88
89
90
import json
import re
import sys
import time
import warnings
import execjs
import requests
from datetime import datetime, timedelta
from urllib3.exceptions import InsecureRequestWarning
from bs4 import BeautifulSoup
warnings.filterwarnings('ignore', category=InsecureRequestWarning)
def login(u, p):
session = requests.session()
session.headers.update({'User-Agent': 'User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)'})
url = 'http://cas.bnu.edu.cn/cas/login'
res = session.get(url)
lt = re.search('name="lt" value="(. )"', res.text).group(1)
execution = re.search('name="execution" value="(. ?)"', res.text).group(1)
payload = {
'rsa': func_des.call("strEnc", u p lt, '1', '2', '3'),
'ul': len(u),
'pl': len(p),
'lt': lt,
'execution': execution,
'_eventId': 'submit'
}
session.post(res.url, data=payload)
session.get('https://seat.lib.bnu.edu.cn/', verify=False)
session.get('http://cas.bnu.edu.cn/cas/login', params={'service': 'http://seat.lib.bnu.edu.cn/cas'})
return session
def self_res(seat_id, start, end, today=False):
url = 'http://seat.lib.bnu.edu.cn/selfRes'
date = datetime.strftime(datetime.now() timedelta(days=1), '%Y-%m-%d') if not today else datetime.strftime(datetime.now(), '%Y-%m-%d')
payload = {
'SYNCHRONIZER_TOKEN': _map(),
'SYNCHRONIZER_URI': '/map',
'date': date,
'seat': seat_id,
'start': start * 60,
'end': end * 60,
'authid': '-1'
}
res = session.post(url, data=payload)
return res
def _map():
url = 'http://seat.lib.bnu.edu.cn/map'
resp = session.get(url)
synchronizer_token = re.search('name="SYNCHRONIZER_TOKEN" value="(. ?)"', resp.text).group(1)
return synchronizer_token
def load_config(path):
with open(path, 'r', encoding='utf-8') as f:
config = json.loads(f.read())
return config
if __name__ == '__main__':
u = '20yydddddxxx'
p = 'enjoyoureverie'
seat_id = 54000
start = 9
end = 21
func_des = execjs.compile(open('./des.js', 'r').read())
session = login(u, p)
t = datetime.strptime(time.strftime('%Y-%m-%d' ' 19:30:00'), '%Y-%m-%d %H:%M:%S')
u_mark = time.mktime(t.timetuple())
while True:
if time.time() > u_mark:
time.sleep(0.200)
resp = self_res(seat_id, start, end)
soup = BeautifulSoup(resp.content, 'lxml')
info = soup.find('div', attrs={'class': 'layoutSeat'}).get_text(separator='\n', strip=True)
print(info)
break
else:
time.sleep(0.200)