-
Notifications
You must be signed in to change notification settings - Fork 0
/
contest_list.py
40 lines (27 loc) · 901 Bytes
/
contest_list.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
import requests
import json
import time
oneday = 86400
def contest_finder():
"""Tells the contest to get the rating changes for"""
url = "https://codeforces.com/api/contest.list?gym=false"
while(True):
response = requests.get(url)
data = response.json()
list = []
for contest in data['result']:
if contest["phase"] == "FINISHED":
break
if(contest["durationSeconds"] < 12500 and abs(contest['relativeTimeSeconds']) < 2 * oneday):
list.append(contest)
if(len(list) == 0):
print("Sleeping for one day")
time.sleep(oneday)
continue
list.sort(key = lambda x: x['startTimeSeconds'])
# for contest in list:
# print(contest)
return list[0]['id']
if(__name__ == "__main__"):
ans = contest_finder()
print(ans)