Skip to content

Commit 366ccd5

Browse files
Quarterly sync with new UI/UX changes
1 parent f801869 commit 366ccd5

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

autokattis/api/__init__.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ def problems(self, show_solved=True, show_partial=True, show_tried=False, show_u
127127
response = f.result()
128128
soup = bs(response.content, features='lxml')
129129
if not soup: continue
130-
table = soup.find('section', class_='strip strip-item-plain').find('table', class_='table2')
130+
try:
131+
table = soup.find('section', class_='strip strip-item-plain').find('table', class_='table2')
132+
except AttributeError:
133+
continue # end of page (no data found)
131134
try:
132135
table_content = table.tbody.find_all('tr')
133136
except AttributeError:
@@ -212,10 +215,19 @@ def problems_v2(self, show_non_ac=False):
212215
columns = row.find_all('td')
213216
if columns and len(columns) > 2:
214217
has_content = True
215-
pid = columns[2].find_all('a')[-1].get('href').split('/')[-1] # might have two links if it belongs to a contest
218+
# column 0: plagiarism
219+
# column 1: time of submission
220+
# column 2: group/team
221+
# column 3: {problem_name} or {contest_name}/{problem_name}
222+
# column 4: status
223+
# column 5: runtime
224+
# column 6: language
225+
# column 7: testcases
226+
# column 8: button to view details
227+
pid = columns[3].find_all('a')[-1].get('href').split('/')[-1].strip() # might have two links if it belongs to a contest
216228
if pid not in pid_set:
217229
link = f"{self.BASE_URL}/problems/{pid}"
218-
name = columns[2].text.split('/')[-1].strip()
230+
name = columns[3].text.split('/')[-1].strip()
219231
pid_set.add(pid)
220232
data.append({
221233
'name': name,
@@ -515,14 +527,23 @@ def stats(self, language='', *languages):
515527
columns = row.find_all('td')
516528
columns_text = [column.text.strip() for column in columns if column.text.strip()]
517529
if columns_text:
530+
# column 0: plagiarism
531+
# column 1: time of submission
532+
# column 2: group/team
533+
# column 3: {problem_name} or {contest_name}/{problem_name}
534+
# column 4: status
535+
# column 5: runtime
536+
# column 6: language
537+
# column 7: testcases
538+
# column 8: button to view details
518539
has_content = True
519-
link = f"{self.BASE_URL}/submissions/{columns[-1].find('a').get('href').split('/')[-1]}"
520-
ts = columns_text[0]
521-
pid = columns[2].find_all('a')[-1].get('href').split('/')[-1] # use find_all as a workaround for contest links
522-
name = columns_text[1].split(' / ')[-1]
523-
runtime = ' '.join(columns_text[3].split()[:-1]) # not converting to float because some TLE solutions (with '>') can also be AC
524-
language = columns_text[4]
525-
tc_pass, tc_full = map(int, columns_text[5].split('/'))
540+
link = f"{self.BASE_URL}/submissions/{columns[8].find('a').get('href').split('/')[-1]}"
541+
ts = columns[1].text.strip()
542+
pid = columns[3].find_all('a')[-1].get('href').split('/')[-1].strip() # might have two links if it belongs to a contest
543+
name = columns[3].text.split(' / ')[-1].strip()
544+
runtime = ' '.join(columns[5].text.split()[:-1]) # not converting to float because some TLE solutions (with '>') can also be AC
545+
language = columns[6].text.strip()
546+
tc_pass, tc_full = map(int, columns[7].text.split('/'))
526547
new_data = {
527548
'name': name,
528549
'timestamp': ts,
@@ -532,7 +553,7 @@ def stats(self, language='', *languages):
532553
'test_case_full': tc_full,
533554
'link': link
534555
}
535-
pts_regex = re.findall(r'[\d\.]+', columns_text[2])
556+
pts_regex = re.findall(r'[\d\.]+', columns[4].text)
536557
if pts_regex:
537558
new_data['score'] = float(pts_regex[0])
538559
if pid not in data:
@@ -601,7 +622,7 @@ def ranklist(self, top_100=False, country=None, university=None):
601622
columns_text = [column.text.strip() for column in columns]
602623
columns_url = [column.find_all('a') for column in columns]
603624

604-
rank = int(columns_text[0])
625+
rank = int(columns_text[0]) if columns_text[0].isdigit() else None
605626
name = columns_text[1]
606627
pts = float(columns_text[-1])
607628
name_urls = columns_url[1]

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='1.6.4',
8+
version='1.6.5',
99
description='Updated Kattis API wrapper',
1010
long_description_content_type="text/markdown",
1111
long_description=README,

test/nus.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313
print(df:=ret.to_df())
1414
df.to_csv('test_nus_problems_v2_all.csv', index=False)
1515

16-
print('=== TEST PROBLEM (SINGLE) ===')
17-
ret = kt.problem('2048') # fetch info about a problem
18-
print(df:=ret.to_df())
19-
df.to_csv('test_nus_problem_single.csv', index=False)
20-
21-
print('=== TEST PROBLEM (MULTIPLE) ===')
22-
ret = kt.problem('2048', 'abinitio', 'dasort') # fetch multiple in one
23-
print(df:=ret.to_df())
24-
df.to_csv('test_nus_problem_multiple.csv', index=False)
25-
2616
print('=== TEST PROBLEM AUTHORS ===')
2717
ret = kt.problem_authors() # list down all problem authors
2818
print(df:=ret.to_df())

0 commit comments

Comments
 (0)