-
Notifications
You must be signed in to change notification settings - Fork 0
/
final.py
85 lines (60 loc) · 1.88 KB
/
final.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
import requests
import json
import time
from master import SendUpdates
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)6
# print("Sleeping for one day")
# time.sleep(oneday)
# continue
#
# list.sort(key = lambda x: x['startTimeSeconds'])
#
# for contest in list:
# print(contest)
#
# contestId = list[0]['id'];
contestId = 1526
start = time.time();
cont_url = 'https://codeforces.com/api/contest.ratingChanges?contestId=' + str(contestId)
while True:
response = requests.get(cont_url)
data = response.json()
# print(data)
end = time.time()
elapsed = end - start
if(elapsed > 3 * oneday):
break
if(data['status'] == "FAILED" or len(data['result']) == 0):
print("Trying again!")
time.sleep(600)
continue
elif(data['status'] == 'OK'):
break
if elapsed > 3 * oneday:
print("ERROR! Contest was faulty")
continue
send_updates = SendUpdates()
send_updates.sendto(cont_url)
print("Going to next contest now!")
time.sleep(10);
break
if(__name__ == "__main__"):
contest_finder()