forked from slvf/BUAA-iClassSignIn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (61 loc) · 2.23 KB
/
main.py
File metadata and controls
66 lines (61 loc) · 2.23 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
import requests
import json
import time
import datetime
student_id = ''
# 获取用户id和sessionId,为查询课表和根据课表打卡做准备
url = 'https://iclass.buaa.edu.cn:8346/app/user/login.action'
para = {
'password': '',
'phone': student_id,
'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