kattis2canvas 0.1.6__py3-none-any.whl → 0.1.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kattis2canvas/cli.py +47 -7
- {kattis2canvas-0.1.6.dist-info → kattis2canvas-0.1.8.dist-info}/METADATA +1 -1
- kattis2canvas-0.1.8.dist-info/RECORD +8 -0
- kattis2canvas-0.1.6.dist-info/RECORD +0 -8
- {kattis2canvas-0.1.6.dist-info → kattis2canvas-0.1.8.dist-info}/WHEEL +0 -0
- {kattis2canvas-0.1.6.dist-info → kattis2canvas-0.1.8.dist-info}/entry_points.txt +0 -0
- {kattis2canvas-0.1.6.dist-info → kattis2canvas-0.1.8.dist-info}/top_level.txt +0 -0
kattis2canvas/cli.py
CHANGED
|
@@ -2,6 +2,7 @@ import collections
|
|
|
2
2
|
import concurrent.futures
|
|
3
3
|
import configparser
|
|
4
4
|
import datetime
|
|
5
|
+
import html
|
|
5
6
|
import os
|
|
6
7
|
import re
|
|
7
8
|
import sys
|
|
@@ -476,6 +477,38 @@ def download_submission(url):
|
|
|
476
477
|
def sanitize(name):
|
|
477
478
|
return re.sub(r"[^\w.]", "_", name)
|
|
478
479
|
|
|
480
|
+
|
|
481
|
+
def get_submission_source(url: str) -> tuple[str, str] | None:
|
|
482
|
+
"""
|
|
483
|
+
Download the source code of a submission if it's less than 8KB.
|
|
484
|
+
Returns (filename, source_code) tuple or None if file is too large or not found.
|
|
485
|
+
"""
|
|
486
|
+
try:
|
|
487
|
+
rsp = web_get(f"https://{config.kattis_hostname}{url}?tab=submitted-files")
|
|
488
|
+
bs = BeautifulSoup(rsp.content, 'html.parser')
|
|
489
|
+
src_div = bs.find(class_="file_source-content-file", recursive=True)
|
|
490
|
+
if not src_div:
|
|
491
|
+
return None
|
|
492
|
+
|
|
493
|
+
h3 = src_div.find("h3")
|
|
494
|
+
filename = os.path.basename(h3.get_text().strip()) if h3 else "source"
|
|
495
|
+
|
|
496
|
+
# Find the source-highlight div containing the actual code
|
|
497
|
+
code_elem = bs.find(class_="source-highlight", recursive=True)
|
|
498
|
+
if not code_elem:
|
|
499
|
+
return None
|
|
500
|
+
|
|
501
|
+
source_code = code_elem.get_text()
|
|
502
|
+
|
|
503
|
+
# Check if less than 8KB
|
|
504
|
+
if len(source_code.encode('utf-8')) > 8 * 1024:
|
|
505
|
+
return None
|
|
506
|
+
|
|
507
|
+
return (filename, source_code)
|
|
508
|
+
except Exception as e:
|
|
509
|
+
warn(f"failed to get source for {url}: {e}")
|
|
510
|
+
return None
|
|
511
|
+
|
|
479
512
|
def get_course(canvas, name, is_active=True) -> Course:
|
|
480
513
|
""" find one course based on partial match """
|
|
481
514
|
course_list = get_courses(canvas, name, is_active)
|
|
@@ -739,7 +772,6 @@ def submissions2canvas(offering, canvas_course, dryrun, assignment_group, sectio
|
|
|
739
772
|
"""
|
|
740
773
|
mirror summary of submission from kattis into canvas as a submission comment.
|
|
741
774
|
"""
|
|
742
|
-
print(force_comment)
|
|
743
775
|
load_config()
|
|
744
776
|
offerings = list(get_offerings(offering))
|
|
745
777
|
if len(offerings) == 0:
|
|
@@ -814,17 +846,25 @@ def submissions2canvas(offering, canvas_course, dryrun, assignment_group, sectio
|
|
|
814
846
|
elif user not in kattis_user2canvas_id:
|
|
815
847
|
warn(f'skipping submission for unknown user {user}')
|
|
816
848
|
elif kattis_submission.date > submissions_by_user[user].last_comment or force_comment:
|
|
849
|
+
href_url = f"https://{config.kattis_hostname}{kattis_submission.url}"
|
|
850
|
+
comment_text = f"{prefix}Submission <a href={href_url}>{href_url}</a> scored {kattis_submission.score} on {kattis_submission.problem}."
|
|
851
|
+
|
|
852
|
+
# Try to include source code if < 8KB
|
|
853
|
+
source_info = get_submission_source(kattis_submission.url)
|
|
854
|
+
if source_info:
|
|
855
|
+
filename, source_code = source_info
|
|
856
|
+
comment_text += f"\n<br/>\n<strong>{html.escape(filename)}</strong>\n<pre>{html.escape(source_code)}</pre>"
|
|
857
|
+
|
|
817
858
|
if dryrun:
|
|
818
|
-
warn(
|
|
819
|
-
|
|
859
|
+
warn(f"would update {kattis_user2canvas_id[kattis_submission.user]} on problem {kattis_submission.problem}:")
|
|
860
|
+
print(comment_text)
|
|
861
|
+
print("---")
|
|
820
862
|
else:
|
|
821
|
-
|
|
822
|
-
submissions_by_user[user].edit(comment={
|
|
823
|
-
'text_comment': f"{prefix}Submission <a href={href_url}>{href_url}</a> scored {kattis_submission.score} on {kattis_submission.problem}."})
|
|
863
|
+
submissions_by_user[user].edit(comment={'text_comment': comment_text})
|
|
824
864
|
info(
|
|
825
865
|
f"updated {submissions_by_user[user]} {kattis_user2canvas_id[kattis_submission.user]} for {assignment.title}")
|
|
826
866
|
else:
|
|
827
|
-
info(f"{user} up to date
|
|
867
|
+
info(f"{user} up to date")
|
|
828
868
|
|
|
829
869
|
|
|
830
870
|
def get_best_submissions(offering: str, assignment_id: str) -> {str: {str: Submission}}:
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
kattis2canvas/__init__.py,sha256=iZxFVdxd7EFidzpHII8RrgHeMtVwrwESqgy4HZKBxPo,109
|
|
2
|
+
kattis2canvas/__main__.py,sha256=GGdT4J5WJQ5MvnJ7m-VX_noR8DGaYXclhjDUIFjW5SY,120
|
|
3
|
+
kattis2canvas/cli.py,sha256=oiy8-bhxUhGuqxPinPA_G6CgKPOZuC31d1PiN-fQMYs,36990
|
|
4
|
+
kattis2canvas-0.1.8.dist-info/METADATA,sha256=68kG8LKV0m5svKyRzJ_bVMSlSvJmYce_5wmY0x7wbyQ,7081
|
|
5
|
+
kattis2canvas-0.1.8.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
+
kattis2canvas-0.1.8.dist-info/entry_points.txt,sha256=V7GPrZNe7aIcu6f_dNo_pCjkuqBQxRzKAQZCNxl9DYg,56
|
|
7
|
+
kattis2canvas-0.1.8.dist-info/top_level.txt,sha256=ZoThmon7y1CR0sTAZndaF2rloBK8xz10mGyz5PUbtCo,14
|
|
8
|
+
kattis2canvas-0.1.8.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
kattis2canvas/__init__.py,sha256=iZxFVdxd7EFidzpHII8RrgHeMtVwrwESqgy4HZKBxPo,109
|
|
2
|
-
kattis2canvas/__main__.py,sha256=GGdT4J5WJQ5MvnJ7m-VX_noR8DGaYXclhjDUIFjW5SY,120
|
|
3
|
-
kattis2canvas/cli.py,sha256=QoJGDVGTWGYAgEAZjifj_2Can_Knl0nYYfomfo9ZCD0,35586
|
|
4
|
-
kattis2canvas-0.1.6.dist-info/METADATA,sha256=xIxE40zA4_pEBbsng4C0iXBVmjo0VSYHeZL98CrDey4,7081
|
|
5
|
-
kattis2canvas-0.1.6.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
-
kattis2canvas-0.1.6.dist-info/entry_points.txt,sha256=V7GPrZNe7aIcu6f_dNo_pCjkuqBQxRzKAQZCNxl9DYg,56
|
|
7
|
-
kattis2canvas-0.1.6.dist-info/top_level.txt,sha256=ZoThmon7y1CR0sTAZndaF2rloBK8xz10mGyz5PUbtCo,14
|
|
8
|
-
kattis2canvas-0.1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|