-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_progress.py
50 lines (39 loc) · 1.37 KB
/
get_progress.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
import json
import os
import requests as r
headers = {
'origin': 'https://hack.lug.ustc.edu.cn',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36',
'referer': 'https://hack.lug.ustc.edu.cn/board/',
'cookie': 'coooooooooookie',
'x-csrftoken': 'csrfffffffffffffff'
}
url = 'https://hack.lug.ustc.edu.cn/admin/submission/'
def get_progress(user_id):
user_id = int(user_id)
data = f'{{"method":"get_user_progress","args":{{"user":{user_id}}}}}'
_ = r.post(url, data=data, headers=headers).text
return json.loads(_)
def main():
if os.path.exists('users+progress.json'):
with open('users+progress.json', 'r') as f:
progresses = json.load(f) # 断点续传(
else:
with open('users.json', 'r') as f:
progresses = json.load(f)
try:
for user_id in progresses.keys():
print(user_id)
if 'progress' in progresses[user_id]:
continue
else:
progress = get_progress(user_id)
print(progress)
progresses[user_id]['progress'] = progress
except Exception as e:
print(e)
finally:
with open('users+progress.json', 'w') as f:
json.dump(progresses, f, indent=4)
if __name__ == '__main__':
main()