forked from slvf/BUAA-iClassSignIn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_ver.py
More file actions
120 lines (100 loc) · 3.22 KB
/
password_ver.py
File metadata and controls
120 lines (100 loc) · 3.22 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
import requests
import re
import json
import time
import datetime
stu_id = ''
stu_pwd = ''
params = {
'service': 'https://iclass.buaa.edu.cn:8346/',
}
response = requests.get('https://sso.buaa.edu.cn/login', params=params)
pattern = r'http://\d+\.\d+\.\d+\.\d+:\d+'
match = re.search(pattern, str(response.cookies))
if match:
cookie_ip = str(match.group())
else:
print("出现了未知bug")
exit(0)
pattern = r'<input name="execution" value="([^"]+)"/>'
match = re.search(pattern, response.text)
if match:
ex = match.group(1)
else:
print("出现了未知bug")
exit(0)
cookies = {
'_7da9a': cookie_ip,
}
data = {
'username': stu_id,
'password': stu_pwd,
'submit': '登录',
'type': 'username_password',
'execution': ex,
'_eventId': 'submit',
}
response = requests.post('https://sso.buaa.edu.cn/login', cookies=cookies, data=data, allow_redirects=True)
pattern = r'loginName=([A-F0-9]+)'
match = re.search(pattern, response.url)
if match:
phone = match.group(1)
else:
print("出现了未知bug")
exit(0)
# 获取用户id和sessionId,为查询课表和根据课表打卡做准备
url = 'https://iclass.buaa.edu.cn:8346/app/user/login_buaa.action'
para = {
'password': '',
'phone': phone,
'userLevel': '1',
'verificationType': '2',
'verificationUrl': ''
}
res = requests.get(url=url, params=para)
userData = json.loads(res.text)
userId = userData['result']['id']
sessionId = userData['result']['sessionId']
cnt = 0 # 连续没课的天数,超过7天说明放假了
today = datetime.datetime.today()
for i in range(120):
if cnt == 7:
break
date = today + datetime.timedelta(days=i)
dateStr = date.strftime('%Y%m%d')
# 查询课表
url = 'https://iclass.buaa.edu.cn:8346/app/course/get_stu_course_sched.action'
para = {
'dateStr': dateStr,
'id': userId
}
headers = {
'sessionId': sessionId,
}
res = requests.get(url=url, params=para, headers=headers)
json_data = json.loads(res.text)
if json_data['STATUS'] == '0':
cnt = 0
for item in json_data['result']:
courseSchedId = item['id']
params = {
'id': userId
}
current_timestamp_seconds = time.time()
current_timestamp_milliseconds = int(current_timestamp_seconds * 1000)
str = f'http://iclass.buaa.edu.cn:8081/app/course/stu_scan_sign.action?courseSchedId={courseSchedId}×tamp={current_timestamp_milliseconds}'
r = requests.post(url=str, params=params)
classBeginTime = item['classBeginTime']
classEndTime = item['classEndTime']
date = classBeginTime[:10]
begin = classBeginTime[11:16]
end = classEndTime[11:16]
if r.ok:
data = json.loads(r.text)
if data['STATUS'] == '1' :
print(f"疑似这节课没开扫码签到:{date}\t{item['courseName']}\t{begin}-{end}")
print(f"已打卡:{date}\t{item['courseName']}\t{begin}-{end}")
else:
print(f"不知道发生什么了但是打卡失败了喵:{date}\t{item['courseName']}\t{begin}-{end}")
else:
cnt += 1