Skip to content

Commit

Permalink
Database and statistic bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellDash332 committed Nov 8, 2024
1 parent 50afb6e commit b760704
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
18 changes: 12 additions & 6 deletions autokattis/api/databasemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ def __init__(self, user):
print('[database] Listed all available languages!', flush=True)

self.COUNTRIES = {}
self.UNIVERSITIES = {}
soup = user.get_soup_response(f'{user.get_base_url()}/ranklist')
soup = user.get_soup_response(f'{user.get_base_url()}/ranklist/countries')
for script in soup.find_all('script'):
for name, code in re.findall('text: "([^"]*)",url: "([^"]*)"', script.text):
for name, code in re.findall('"text": "([^"]*)","url": "([^"]*)"', script.text):
_, cat, code = code.replace('\\', '').split('/')
name = name.encode().decode('unicode_escape')
if cat == 'countries': self.COUNTRIES[code] = name
elif cat == 'universities': self.UNIVERSITIES[code] = name
print('[database] Listed all available countries!', flush=True)
print('[database] Listed all available universities!', flush=True)
print(f'[database] Listed all {len(self.COUNTRIES)} available countries!', flush=True)

self.UNIVERSITIES = {}
soup = user.get_soup_response(f'{user.get_base_url()}/ranklist/universities')
for script in soup.find_all('script'):
for name, code in re.findall('"text": "([^"]*)","url": "([^"]*)"', script.text):
_, cat, code = code.replace('\\', '').split('/')
name = name.encode().decode('unicode_escape')
if cat == 'universities': self.UNIVERSITIES[code] = name
print(f'[database] Listed all {len(self.UNIVERSITIES)} available universities!', flush=True)

def get_languages(self):
return self.LANGUAGES
Expand Down
2 changes: 1 addition & 1 deletion autokattis/api/nuskattis.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def problem(self, problem_ids, download_files=False, *bc_args):
# if there are multiple offerings, just take the first one because they share the same leaderboard
data['statistics'] = {}
soup = self.get_soup_response(f'{dest_urls[0]}/statistics')
category_map = {option.get('value'):[option.text, option.get('data-title')] for option in soup.find_all('option')}
category_map = {option.get('value')[1:]:[option.text, option.get('data-title')] for option in soup.find_all('option')}
for section in soup.find_all('section', class_='strip strip-item-plain'):
table = section.find('table')
section_id = section.get('id')
Expand Down
2 changes: 1 addition & 1 deletion autokattis/api/openkattis.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def problem(self, problem_ids, download_files=False, *bc_args):
# statistics
data['statistics'] = {}
soup = self.get_soup_response(f'{self.get_base_url()}/problems/{problem_id}/statistics')
category_map = {option.get('value'):[option.text, option.get('data-title')] for option in soup.find_all('option')}
category_map = {option.get('value')[1:]:[option.text, option.get('data-title')] for option in soup.find_all('option')}
for section in soup.find_all('section', class_='strip strip-item-plain'):
table = section.find('table')
section_id = section.get('id')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup_args = dict(
name='autokattis',
version='2.0.1',
version='2.0.2',
description='Updated Kattis API wrapper',
long_description_content_type="text/markdown",
long_description=README,
Expand Down

0 comments on commit b760704

Please # to comment.