-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcron.py
119 lines (89 loc) · 3.34 KB
/
cron.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
from utils.exception import ValidationException
from .api import (contest_list, contest_ratingChanges, contest_standings,
user_ratedList)
from .models_utils import (create_or_update_contest, create_or_update_problem,
create_or_update_user, update_and_save_contest_data)
from .models import contest, user_contest_rank
from .utils import send_error_mail, sendMailToUsers
def ratingChangeReminder():
try:
contests = contest_list()
except:
return
limit = 1
for codeforces_contest in contests:
try:
response = contest_ratingChanges(codeforces_contest['id'])
new_contest = create_or_update_contest(codeforces_contest)
if len(response) == 0:
continue
elif not new_contest.isUpdated:
new_contest.isUpdated = True
new_contest.save()
update_and_save_contest_data(response, new_contest)
sendMailToUsers(response, new_contest)
elif limit:
limit -= 1
else:
break
except:
check_contest = contest.objects.filter(contestId=id)
if not check_contest.exists():
continue
elif check_contest[0].isUpdated:
break
else:
continue
def codeforces_update_users():
try:
response = user_ratedList(activeOnly=True)
except ValidationException as err:
send_error_mail(str(err))
return
for codeforces_user in response:
create_or_update_user(codeforces_user)
def codeforces_update_problems():
try:
contests = contest_list()
except ValidationException as err:
return
for codeforces_contest in contests:
try:
response = contest_standings(contestId=codeforces_contest['id'],
count=1)
except ValidationException as err:
continue
create_or_update_contest(codeforces_contest)
for contest_problem in response['problems']:
create_or_update_problem(contest_problem)
try:
contests = contest_list(gym=True)
except ValidationException as err:
return
for codeforces_contest in contests:
try:
response = contest_standings(contestId=codeforces_contest['id'],
count=1)
except ValidationException as err:
continue
create_or_update_contest(codeforces_contest, contest_type='G')
for contest_problem in response['problems']:
create_or_update_problem(contest_problem, type="gym")
def codeforces_update_contest():
try:
response = contest_list()
except ValidationException as err:
send_error_mail(str(err))
return
response.reverse()
for codeforces_contest in response[-50:]:
try:
contest_rating_change = contest_ratingChanges(
codeforces_contest['id'])
except:
continue
new_contest = create_or_update_contest(codeforces_contest)
if user_contest_rank.objects.filter(contest=new_contest).count() == \
len(contest_rating_change):
continue
update_and_save_contest_data(contest_rating_change, new_contest)