-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
133 lines (106 loc) · 4.29 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
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
from requests import Session
import re
import json
import time
host = 'https://iscc.isclab.org.cn'
username = ""
password = ""
ss = Session()
ss.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
ptnProfile = re.compile(r'<h1 id="team-id">(.*?)</h1>\s+<h3 class="text-center">总积分为:(\d*?),排在(\d*?)位。</h3>')
def updateUserList():
id = (int(list(userList.keys())[-1]) if len(userList) > 0 else 0) + 1
err_status = 0
while True:
ret = ss.get(f'{host}/team/{id}')
if ret.status_code == 200:
name, score, ranking = ptnProfile.findall(ret.text)[0]
if name == '' and score == '':
err_status += 1
if err_status >= 20:
return True
else:
err_status = 0
userList[f'{id}'] = {'name': name, 'score': 0, 'friends': {}}
print(id, name)
else:
raise Exception(f'HTTP {ret.status_code}')
id += 1
pass
def updateQuestionList(type, valueName):
ret = ss.get(f'{host}/{type}')
if ret.status_code == 200:
ret = ret.json()
for q in ret['game']:
if q['category'] not in valueName.keys():
valueName[q['category']] = {}
retret = ss.get(f'{host}/{type}/{q["id"]}')
if retret.status_code == 200:
retret = retret.json()
valueName[q['category']][q['id']] = {
'name': retret['name'],
'score': retret['value'],
'description': retret['description'],
'files': retret['files'],
'solves': []
}
if type == "arenas":
valueName[q['category']][q['id']]['author'] = retret['author']
# print(q['category'], q['id'], retret['name'])
else:
raise Exception(f'HTTP {retret.status_code}')
pass
else:
raise Exception(f'HTTP {ret.status_code}')
pass
def updateQuestionsolve(type, valueName):
for category in valueName.keys():
for id in valueName[category].keys():
ret = ss.get(f'{host}/{type}/{id}/solves')
if ret.status_code == 200:
ret = ret.json()
valueName[category][id]['solves'] = ret['teams']
if type == "are":
for i in valueName[category][id]['solves']:
if i["name"] == valueName[category][id]["author"]:
valueName[category][id]['solves'].remove(i)
print(category, id, "成功排除擂台赛中出题人自动解题造成的误差")
break
for slove in valueName[category][id]['solves']:
userList[f"{slove['id']}"]['score'] += valueName[category][id]['score']
# print(category, id, valueName[category][id]['solves'])
pass
def updateChallengeList():
updateQuestionList('chals', challengeList)
def updateChallengesolve():
updateQuestionsolve('chal', challengeList)
pass
def updateArenaList():
updateQuestionList('arenas', arenaList)
pass
def updateArenasolve():
updateQuestionsolve('are', arenaList)
pass
def main():
for id in userList:
userList[id]['score'] = 0
updateUserList()
assert ss.post(f'{host}/login', data={'name': username, 'password': password}, allow_redirects=False).status_code == 302
updateChallengeList()
updateChallengesolve()
with open('challenge.json', 'w', encoding='UTF-8') as f:
f.write(json.dumps(challengeList, ensure_ascii=False))
updateArenaList()
updateArenasolve()
with open('arena.json', 'w', encoding='UTF-8') as f:
f.write(json.dumps(arenaList, ensure_ascii=False))
with open('user.json', 'w', encoding='UTF-8') as f:
f.write(json.dumps(userList, ensure_ascii=False))
with open('status.json', 'w', encoding='UTF-8') as f:
f.write(json.dumps({'updateTime': time.time()}, ensure_ascii=False))
if __name__ == '__main__':
with open('user.json', 'r', encoding='UTF-8') as f:
userList = json.loads(f.read(-1))
challengeList = {}
arenaList = {}
main()