5.1 KiB
Classes
Themis
Creates the initial connection to Themis.
Usage
from temmies.Themis import Themis
themis = Themis("s-number", "password")
Methods
login()
Logs in to Themis. Runs automatically when the class is initialized.
get_year(start, end)
Returns an instance of a Year
(academic year) between start
and end
.
year = themis.get_year(2023, 2024)
all_years()
Returns a list of Year
instances corresponding to all years visible to the user.
years = themis.all_years()
I don't see why you would need this, but it's here.
Year
Usage
year = themis.get_year(2023, 2024)
Methods
get_course(name)
Returns an instance of a Course
with the name name
.
pf = year.get_course("Programming Fundamentals (for CS)")
all_courses()
Returns a list of Course
instances corresponding to all courses visible to the user in a given Year
.
courses = year.all_courses()
Course
Usage
pf = year.get_course("Programming Fundamentals (for CS)")
print(pf.info) # <- course info attribute
assignments = pf.get_groups()
Methods
get_groups(full=False)
Returns a list of ExerciseGroup
instances corresponding to all exercise groups visible to the user in a given Course
. Default argument is full=False
, which will only return the (name, link) of each exercise and folder in the group. If full=True
, it will traverse the whole course.
You can traverse the course in both cases, although in different ways.
When you have fully traversed the course, you can access everything via indices and the exercises
and folders
attributes of the ExerciseGroup
instances:
ai_group = ai_course.get_groups(full=True)
exercise = ai_group[7].exercises[1] # Week 11 -> Suitcase packing
exercise.submit("suitcase.py", silent=False)```
This is equivalent to the case in which we don't traverse the full course using get_group
like so:
ai_group = ai_course.get_group("Week 11")
exercise = ai_group.get_group("Suitcase packing")
exercise.submit("suitcase.py", silent=False)
get_group(name, full=False)
Returns an instance of an ExerciseGroup
with the name name
. Default argument is full=False
, which will only return the (name, link) of each exercise and folder in the group. If full=True
, it will traverse the whole group.
week1 = pf.get_group("Week 1")
ExerciseGroup
Setting the full
flag to True
will traverse the whole course.
You can traverse the course in both cases
- Both folders and exercises are represented as
ExerciseGroup
instances. - Folders will have the
am_exercise
attribute set toFalse
. - Folders can have the
download_files
method called on them. - Exercises can have the
submit
,download_files
anddownload_tcs
method called on them.
Example of folder traversal
Let's say we have a folder structure like this:
- Course Name
- Week 1
- Exercise 1
- Exercise 2
- Part 1
- Part 2
- Week 2
- Exercise 1
- Exercise 2
And we want to get to Part 2
of Week 1
's Exercise 2
. We would do this:
pf = year.get_course("Programming Fundamentals (for CS)")
assignments = pf.get_groups()
week1 = assignments[0] # Week 1
exercise2 = week1.folders[1] # Exercise 2
part2 = exercise2.exercises[1] # Part 2
# Or, if you dont want to traverse the whole course:
week1 = pf.get_group("Week 1")
exercise2 = week1.get_group("Exercise 2")
part2 = exercise2.get_group("Part 2")
Methods
download_files(path=".")
Downloads all files in the exercise group to a directory path
. Defaults to the current directory.
assignment.download_files()
download_tcs(path=".")
Downloads all test cases in the exercise group to a directory path
. Defaults to the current directory.
assignment.download_tcs()
get_group(name, full=False)
This is used when you want to traverse the course dynamically(not recurse through the whole thing). Of course, you can use it even if you've traversed the whole course, but that would overcomplicate things.
# Week 1 -> Exercise 2 -> Part 2
week1 = pf.get_groups("Week 1")
exercise2 = week1.get_group("Exercise 2")
part2 = exercise2.get_group("Part 2")
# This is equivalent to(but faster than):
week1 = pf.get_groups("Week 1", full=True)
exercise2 = week1[1]
part2 = exercise2[1]
submit(files)
Submits the files to the exercise group. Default arguments are judge=True
, wait=True
and silent=True
. judge
will judge the submission instantly, and wait
will wait for the submission to finish. Turning off silent
will print the submission status dynamically.
suitcase = ai.get_group("Week 11")
suitcase[7].exercises[1].submit("suitcase.py", silent=False)
# Or
ai.get_group("Week 11").get_group("Suitcase packing").submit("suitcase.py", silent=False)
>>> 1: ✅
>>> 2: ✅
>>> 3: ✅
>>> 4: ✅
>>> 5: ✅
>>> 6: ✅
>>> 7: ✅
>>> 8: ✅
>>> 9: ✅
>>> 10: ✅