Skip to content

Commit b760704

Browse files
Database and statistic bugfixes
1 parent 50afb6e commit b760704

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

autokattis/api/databasemanager.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ def __init__(self, user):
1515
print('[database] Listed all available languages!', flush=True)
1616

1717
self.COUNTRIES = {}
18-
self.UNIVERSITIES = {}
19-
soup = user.get_soup_response(f'{user.get_base_url()}/ranklist')
18+
soup = user.get_soup_response(f'{user.get_base_url()}/ranklist/countries')
2019
for script in soup.find_all('script'):
21-
for name, code in re.findall('text: "([^"]*)",url: "([^"]*)"', script.text):
20+
for name, code in re.findall('"text": "([^"]*)","url": "([^"]*)"', script.text):
2221
_, cat, code = code.replace('\\', '').split('/')
2322
name = name.encode().decode('unicode_escape')
2423
if cat == 'countries': self.COUNTRIES[code] = name
25-
elif cat == 'universities': self.UNIVERSITIES[code] = name
26-
print('[database] Listed all available countries!', flush=True)
27-
print('[database] Listed all available universities!', flush=True)
24+
print(f'[database] Listed all {len(self.COUNTRIES)} available countries!', flush=True)
25+
26+
self.UNIVERSITIES = {}
27+
soup = user.get_soup_response(f'{user.get_base_url()}/ranklist/universities')
28+
for script in soup.find_all('script'):
29+
for name, code in re.findall('"text": "([^"]*)","url": "([^"]*)"', script.text):
30+
_, cat, code = code.replace('\\', '').split('/')
31+
name = name.encode().decode('unicode_escape')
32+
if cat == 'universities': self.UNIVERSITIES[code] = name
33+
print(f'[database] Listed all {len(self.UNIVERSITIES)} available universities!', flush=True)
2834

2935
def get_languages(self):
3036
return self.LANGUAGES

autokattis/api/nuskattis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def problem(self, problem_ids, download_files=False, *bc_args):
254254
# if there are multiple offerings, just take the first one because they share the same leaderboard
255255
data['statistics'] = {}
256256
soup = self.get_soup_response(f'{dest_urls[0]}/statistics')
257-
category_map = {option.get('value'):[option.text, option.get('data-title')] for option in soup.find_all('option')}
257+
category_map = {option.get('value')[1:]:[option.text, option.get('data-title')] for option in soup.find_all('option')}
258258
for section in soup.find_all('section', class_='strip strip-item-plain'):
259259
table = section.find('table')
260260
section_id = section.get('id')

autokattis/api/openkattis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def problem(self, problem_ids, download_files=False, *bc_args):
349349
# statistics
350350
data['statistics'] = {}
351351
soup = self.get_soup_response(f'{self.get_base_url()}/problems/{problem_id}/statistics')
352-
category_map = {option.get('value'):[option.text, option.get('data-title')] for option in soup.find_all('option')}
352+
category_map = {option.get('value')[1:]:[option.text, option.get('data-title')] for option in soup.find_all('option')}
353353
for section in soup.find_all('section', class_='strip strip-item-plain'):
354354
table = section.find('table')
355355
section_id = section.get('id')

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup_args = dict(
77
name='autokattis',
8-
version='2.0.1',
8+
version='2.0.2',
99
description='Updated Kattis API wrapper',
1010
long_description_content_type="text/markdown",
1111
long_description=README,

0 commit comments

Comments
 (0)