-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsolved_update.py
151 lines (137 loc) · 4.95 KB
/
solved_update.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import requests
import bs4
import os, django, json
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "codedigger.settings")
django.setup()
from lists.models import Solved
from user.models import Profile, User
from problem.models import Problem
from codeforces.api import user_status
from utils.exception import ValidationException
def codechef(user, prob):
if user is None or Solved.objects.filter(problem=prob, user=user).exists():
return
codechef_handle = Profile.objects.get(owner=user).codechef
if codechef_handle is None:
return
url = 'https://www.codechef.com/users/' + str(codechef_handle)
res = requests.get(url)
soup = bs4.BeautifulSoup(res.content, 'html.parser')
problems_solved = soup.find(
'section', {'class': 'rating-data-section problems-solved'})
if not problems_solved or problems_solved.find(
'h5').text == 'Fully Solved (0)':
return
probset = set([])
for ele in problems_solved.find('article').find_all('a'):
probset.add(ele.text)
if prob.prob_id in probset:
Solved.objects.create(user=user, problem=prob)
def spoj(user, prob):
if user is None or Solved.objects.filter(problem=prob, user=user).exists():
return
spoj_handle = Profile.objects.get(owner=user).spoj
if spoj_handle == None:
return
url = 'https://www.spoj.com/status/' + str(
prob.prob_id) + ',' + str(spoj_handle)
res = requests.get(url)
soup = bs4.BeautifulSoup(res.content, 'html.parser')
status = soup.find('td', {'status': '15'})
if status is not None:
Solved.objects.create(user=user, problem=prob)
def codeforces(user):
if user is None:
return
cf_handle = Profile.objects.get(owner=user).codeforces
if cf_handle == None:
return
try:
submission_user = user_status(cf_handle)
except ValidationException:
return
limit = 10
for ele in submission_user:
if 'verdict' not in ele or 'contestId' not in ele or ele[
'verdict'] != 'OK':
continue
prob_id = str(ele['problem']['contestId']) + str(
ele['problem']['index'])
prob = Problem.objects.filter(prob_id=prob_id, platform='F')
if not prob.exists():
continue
solve, created = Solved.objects.get_or_create(user=user,
problem=prob[0])
if not created:
limit -= 1
if limit <= 0:
break
continue
# url = 'https://codeforces.com/api/user.status?handle=' + str(cf_handle)
# res = requests.get(url)
# if res.status_code != 200:
# return
# req = res.json()
# if req['status'] != 'OK':
# return
def uva(user):
if user is None:
return
uva_id = Profile.objects.get(owner=user).uva_id
if uva_id is None:
return
url1 = "https://uhunt.onlinejudge.org/api/subs-user/" + str(uva_id)
req1 = requests.get(url1).json()
sorted_req1 = sorted(req1['subs'], key=lambda k: k[4], reverse=True)
limit = 10
for ele in sorted_req1:
if str(ele[2]) != '90':
continue
prob = Problem.objects.filter(prob_id=str(ele[1]), platform='U')
if not prob.exists():
continue
solve, created = Solved.objects.get_or_create(user=user,
problem=prob[0])
if not created:
limit -= 1
if limit <= 0:
break
continue
def atcoder(user):
if user is None:
return
atcoder_handle = Profile.objects.get(owner=user).atcoder
if atcoder_handle is None:
return
url = 'https://kenkoooo.com/atcoder/atcoder-api/results?user=' + str(
atcoder_handle)
req = requests.get(url).json()
sorted_req = sorted(req, key=lambda k: k['epoch_second'], reverse=True)
limit = 10
for ele in sorted_req:
if ele['result'] != "AC":
continue
prob = Problem.objects.filter(prob_id=ele['problem_id'], platform='A')
if not prob.exists():
continue
solve, created = Solved.objects.get_or_create(user=user,
problem=prob[0])
if not created:
limit -= 1
if limit <= 0:
break
continue
def atcoder_scraper_check(user, prob):
if user is None or Solved.objects.filter(problem=prob, user=user).exists():
return
atcoder_handle = Profile.objects.get(owner=user).atcoder
if atcoder_handle is None:
return
contest = prob.contest_id
taskname = prob.prob_id
URL = "https://atcoder.jp/contests/" + contest + "/submissions/?f.User=" + user.username + "&" + "f.Task=" + taskname
r = requests.get(URL)
soup = bs4.BeautifulSoup(r.content, 'html5lib')
check = soup.find_all("span", {"class": "label label-success"})
if check:
Solved.objects.create(user=user, problem=prob)