2024-04-06 16:16:23 +02:00
# Classes
---
2024-11-17 19:50:05 +01:00
2024-04-06 16:16:23 +02:00
## `Themis`
Creates the initial connection to Themis.
### Usage
```python
2024-04-21 20:37:07 +02:00
from temmies.themis import Themis
2024-04-06 16:16:23 +02:00
2024-11-17 21:57:07 +01:00
themis = Themis("s-number")
2024-04-06 16:16:23 +02:00
```
2024-11-17 21:57:07 +01:00
On the first run, you will be prompted for your password. Then, on the next run(s), you will be able to log in automatically, as the password is stored in the system keyring. If you want to delete it [click here ](https://www.google.com/search?hl=en&q=delete%20a%20password%20from%20keyring ).
2024-04-06 16:16:23 +02:00
### Methods
#### `login()`
Logs in to Themis. Runs automatically when the class is initialized.
2024-11-18 20:17:26 +01:00
#### `get_year(year_path)`
Returns an instance of a [`Year` ](#year ) for the academic year specified by `year_path` .
2024-04-06 16:16:23 +02:00
```python
2024-04-10 18:48:21 +02:00
year = themis.get_year(2023, 2024)
2024-04-06 16:16:23 +02:00
```
2024-04-10 18:48:21 +02:00
#### `all_years()`
2024-04-06 16:16:23 +02:00
Returns a list of `Year` instances corresponding to all years visible to the user.
```python
2024-04-10 18:48:21 +02:00
years = themis.all_years()
2024-04-06 16:16:23 +02:00
```
2024-11-18 20:17:26 +01:00
2024-04-06 16:16:23 +02:00
----
## `Year`
### Usage
```python
2024-04-10 18:48:21 +02:00
year = themis.get_year(2023, 2024)
2024-04-06 16:16:23 +02:00
```
### Methods
2024-11-18 20:17:26 +01:00
#### `get_course(course_title)`
Returns an instance of a [`Course` ](#course ) with the title `course_title` .
2024-04-06 16:16:23 +02:00
```python
2024-04-10 18:48:21 +02:00
pf = year.get_course("Programming Fundamentals (for CS)")
2024-04-06 16:16:23 +02:00
```
2024-11-18 20:17:26 +01:00
#### `get_course_by_tag(course_tag)`
Returns an instance of a [`Course` ](#course ) using the course identifier `course_tag` .
```python
ai_course = year.get_course_by_tag("adinc-ai")
```
2024-04-10 18:48:21 +02:00
#### `all_courses()`
2024-04-06 16:16:23 +02:00
Returns a list of `Course` instances corresponding to all courses visible to the user in a given `Year` .
```python
2024-04-10 18:48:21 +02:00
courses = year.all_courses()
2024-04-06 16:16:23 +02:00
```
----
## `Course`
### Usage
```python
2024-04-10 18:48:21 +02:00
pf = year.get_course("Programming Fundamentals (for CS)")
assignments = pf.get_groups()
2024-04-06 16:16:23 +02:00
```
### Methods
2024-04-10 18:48:21 +02:00
#### `get_groups(full=False)`
2024-11-18 20:17:26 +01:00
Returns a list of `ExerciseGroup` or `Group` instances corresponding to all items visible to the user in a given `Course` . The default argument is `full=False` , which will only return the top-level (name, link) of each item. If `full=True` , it will traverse the whole course.
2024-04-06 16:16:23 +02:00
```python
2024-11-18 20:17:26 +01:00
ai_groups = ai_course.get_groups(full=True)
exercise = ai_groups[7].exercises[1]
exercise.submit(["solution.py"], silent=False)
2024-04-09 16:18:54 +02:00
```
2024-11-18 20:17:26 +01:00
#### `get_group(name, full=False)`
Returns an instance of an `ExerciseGroup` or `Group` with the name `name` . The default argument is `full=False` , which will only return the (name, link) of the group. If `full=True` , it will traverse the whole group.
2024-04-09 16:18:54 +02:00
```python
2024-11-18 20:17:26 +01:00
week1 = pf.get_group("Week 1")
2024-04-09 16:18:54 +02:00
```
2024-11-18 20:17:26 +01:00
#### `create_group(item_data)`
Creates and returns a `Group` or `ExerciseGroup` instance based on `item_data` .
2024-04-09 16:18:54 +02:00
```python
2024-11-18 20:17:26 +01:00
group = course.create_group(item_data)
2024-04-06 16:16:23 +02:00
```
2024-11-17 19:50:05 +01:00
----
2024-04-06 16:16:23 +02:00
2024-11-18 20:17:26 +01:00
## `Group`
2024-04-06 16:16:23 +02:00
2024-11-18 20:17:26 +01:00
Represents an item in Themis, which can be either a folder (non-submittable) or an assignment (submittable).
2024-04-06 16:16:23 +02:00
2024-11-18 20:17:26 +01:00
### Methods
#### `get_items()`
Returns all items (groups and assignments) under this group.
2024-04-06 16:16:23 +02:00
```python
2024-11-18 20:17:26 +01:00
items = week1.get_items()
2024-04-06 16:16:23 +02:00
```
2024-11-18 20:17:26 +01:00
#### `get_item_by_title(title)`
Returns a single item by its title (case-insensitive).
2024-04-06 16:16:23 +02:00
```python
2024-11-18 20:17:26 +01:00
item = week1.get_item_by_title("Exercise 2")
2024-04-06 16:16:23 +02:00
```
2024-11-18 20:17:26 +01:00
#### `get_status(text=False)`
Retrieves the status of the group. When `text=True` , returns the status as strings. Otherwise, returns submission objects or strings.
2024-04-06 16:16:23 +02:00
```python
2024-11-18 20:17:26 +01:00
status = group.get_status()
leading_submission = status["leading"]
2024-04-06 16:16:23 +02:00
```
2024-11-18 20:17:26 +01:00
#### `download_files(path=".")`
Downloads all files available for this group to a directory `path` . Defaults to the current directory.
2024-04-09 16:18:54 +02:00
```python
2024-11-18 20:17:26 +01:00
group.download_files()
2024-11-17 19:50:05 +01:00
```
2024-04-09 16:18:54 +02:00
2024-11-18 20:17:26 +01:00
#### `download_tcs(path=".")`
Downloads all test cases for this group to a directory `path` . Defaults to the current directory.
2024-04-06 16:16:23 +02:00
```python
2024-11-18 20:17:26 +01:00
group.download_tcs()
2024-04-06 16:16:23 +02:00
```
2024-04-08 22:28:01 +02:00
2024-11-18 20:17:26 +01:00
#### `submit(files, judge=True, wait=True, silent=True)`
Submits the files to the group. Default arguments are `judge=True` , `wait=True` , and `silent=True` .
2024-04-20 21:35:09 +02:00
```python
2024-11-18 20:17:26 +01:00
group.submit(["solution.py"], silent=False)
2024-11-17 19:50:05 +01:00
```
2024-04-20 21:35:09 +02:00
2024-11-18 20:17:26 +01:00
----
## `ExerciseGroup`
Represents a submittable exercise. Inherits from `Group` .
### Additional Methods
#### `submit(files)`
Submits files to the exercise. Raises an error if the item is not submittable.
2024-04-20 21:35:09 +02:00
2024-11-17 19:50:05 +01:00
```python
2024-11-18 20:17:26 +01:00
exercise.submit(["solution.py"])
2024-04-20 21:35:09 +02:00
```
2024-11-17 19:50:05 +01:00
----
2024-04-20 21:35:09 +02:00
## `Submission`
2024-11-18 20:17:26 +01:00
Represents a submission for a specific exercise.
2024-04-20 21:35:09 +02:00
### Methods
2024-11-17 19:50:05 +01:00
#### `get_test_cases()`
Returns a dictionary of test cases and their statuses.
2024-04-20 21:35:09 +02:00
```python
2024-11-17 19:50:05 +01:00
test_cases = submission.get_test_cases()
2024-04-20 21:35:09 +02:00
```
2024-11-17 19:50:05 +01:00
#### `get_info()`
2024-11-18 20:17:26 +01:00
Returns detailed information about the submission.
2024-04-20 21:35:09 +02:00
```python
2024-11-17 19:50:05 +01:00
info = submission.get_info()
2024-04-20 21:35:09 +02:00
```
2024-11-17 19:50:05 +01:00
#### `get_files()`
Returns a list of uploaded files in the format `(name, URL)` .
2024-04-20 21:35:09 +02:00
```python
2024-11-17 19:50:05 +01:00
files = submission.get_files()
2024-04-20 21:35:09 +02:00
```