diff --git a/autokattis/api/databasemanager.py b/autokattis/api/databasemanager.py index 089da23..35dbc63 100644 --- a/autokattis/api/databasemanager.py +++ b/autokattis/api/databasemanager.py @@ -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 diff --git a/autokattis/api/nuskattis.py b/autokattis/api/nuskattis.py index 56ed8b5..b0318e8 100644 --- a/autokattis/api/nuskattis.py +++ b/autokattis/api/nuskattis.py @@ -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') diff --git a/autokattis/api/openkattis.py b/autokattis/api/openkattis.py index 6e20590..1dcb99c 100644 --- a/autokattis/api/openkattis.py +++ b/autokattis/api/openkattis.py @@ -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') diff --git a/setup.py b/setup.py index 1713768..9329e00 100644 --- a/setup.py +++ b/setup.py @@ -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,