temmies/docs/api.md

188 lines
4.4 KiB
Markdown
Raw Normal View History

# Classes
---
## `Themis`
Creates the initial connection to Themis.
### Usage
```python
from temmies.themis import Themis
themis = Themis("s-number")
```
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).
### 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`.
```python
year = themis.get_year(2023, 2024)
```
#### `all_years()`
Returns a list of `Year` instances corresponding to all years visible to the user.
```python
years = themis.all_years()
```
2024-11-18 20:17:26 +01:00
----
## `Year`
### Usage
```python
year = themis.get_year(2023, 2024)
```
### 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`.
```python
pf = year.get_course("Programming Fundamentals (for CS)")
```
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")
```
#### `all_courses()`
Returns a list of `Course` instances corresponding to all courses visible to the user in a given `Year`.
```python
courses = year.all_courses()
```
----
## `Course`
### Usage
```python
pf = year.get_course("Programming Fundamentals (for CS)")
assignments = pf.get_groups()
```
### Methods
#### `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.
```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-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.
```python
2024-11-18 20:17:26 +01:00
week1 = pf.get_group("Week 1")
```
2024-11-18 20:17:26 +01:00
#### `create_group(item_data)`
Creates and returns a `Group` or `ExerciseGroup` instance based on `item_data`.
```python
2024-11-18 20:17:26 +01:00
group = course.create_group(item_data)
```
----
2024-11-18 20:17:26 +01:00
## `Group`
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-11-18 20:17:26 +01:00
### Methods
#### `get_items()`
Returns all items (groups and assignments) under this group.
```python
2024-11-18 20:17:26 +01:00
items = week1.get_items()
```
2024-11-18 20:17:26 +01:00
#### `get_item_by_title(title)`
Returns a single item by its title (case-insensitive).
```python
2024-11-18 20:17:26 +01:00
item = week1.get_item_by_title("Exercise 2")
```
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.
```python
2024-11-18 20:17:26 +01:00
status = group.get_status()
leading_submission = status["leading"]
```
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.
```python
2024-11-18 20:17:26 +01:00
group.download_files()
```
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.
```python
2024-11-18 20:17:26 +01:00
group.download_tcs()
```
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-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
```python
2024-11-18 20:17:26 +01:00
exercise.submit(["solution.py"])
2024-04-20 21:35:09 +02: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
#### `get_test_cases()`
Returns a dictionary of test cases and their statuses.
2024-04-20 21:35:09 +02:00
```python
test_cases = submission.get_test_cases()
2024-04-20 21:35:09 +02: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
info = submission.get_info()
2024-04-20 21:35:09 +02:00
```
#### `get_files()`
Returns a list of uploaded files in the format `(name, URL)`.
2024-04-20 21:35:09 +02:00
```python
files = submission.get_files()
2024-04-20 21:35:09 +02:00
```