Skip to content

Commit f35a173

Browse files
committed
Update documentation + add set_lang() method
1 parent aa9d4fe commit f35a173

4 files changed

Lines changed: 530 additions & 300 deletions

File tree

docs/configuration.md

Lines changed: 116 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,94 @@
55
66
## 1. Editing `my_config`
77

8+
### 1.1 Setting the language
9+
10+
Set the language using:
11+
12+
- `untis.my_config.set_lang('en')`
13+
- `untis.my_config.set_lang('de')`
14+
15+
Note: Currently only german (`'de'`) and english (`en`) is supported.
16+
17+
### 1.2 Understanding the objects
18+
19+
`units.my_config` is split into 3 subclasses:
20+
- `timetable_mapping_config (TimeTableMappingConfig)`
21+
- `self.language_config (LanguageConfig)`
22+
- `self.html_style_config (HTMLStyleConfig)`
23+
24+
### 1.3 Modifying specific values
25+
826
Modify the Configuration using `untis.my_config.* = ...`
927

1028
For example:
11-
- `untis.my_config.timetable_html_footer = ...`
12-
- `untis.my_config.two_week_abbreviation = ...`
13-
- `untis.my_config.teacher_mapping = ...`
29+
- `untis.my_config.html_style_config.timetable_html_footer = ...`
30+
- `untis.my_config.language_config.two_week_abbreviation = ...`
31+
- `untis.my_config.timetable_mapping_config.teacher_mapping = ...`
1432
- ...
1533

34+
1635
## 2. Timetable mappings
1736

18-
See [config.py](../untis/config.py) for more info.
37+
Example `personal_timetable_entries`
38+
```python
39+
untis.my_config.timetable_mapping_config.personal_timetable_entries: dict[str, tuple[set[str], set[str]]] = {
40+
'child1': (
41+
# Set of teacher abbreviations
42+
{'T1', 'T2', 'T3', ...},
43+
# Set of subject abbreviations
44+
{'M', 'G', 'E', ...}),
45+
'child2': (
46+
{'T1', 'T2', 'T3', ...},
47+
{'M', 'G', 'E', ...}),
48+
}
49+
```
50+
This allows using `TimeTable.filter_hours_by_personal('child1')` on an existing TimeTable, which only returns the
51+
lessons with certain teachers or subjects connected to it. Useful if your child is in a class, where some pupils attend
52+
lessons that your child doesn't.
53+
54+
Example `teacher_mapping`
55+
```python
56+
untis.my_config.timetable_mapping_config.teacher_mapping: dict[int, tuple[str, str, tuple[str, ...]]] = {
57+
0: ('Unknown', 'N/A', ('/',)), # Always means no teacher, never assign a real name here
58+
# Teacher ID: (full name, abbreviated Name, (Subject abbreviation 1, ...)
59+
3: ('Tom Mister', 'AB', ('M', 'G', 'E')),
60+
8: ('Benjamin Bob', 'CD', ('PS', 'PE', 'FR')),
61+
}
62+
```
63+
64+
This allows the TimeTable to format the name of the teachers correctly. The API technically does have a
65+
`Session.teachers()` function which uses the webuntis `getTeachers` endpoint. However, most student accounts don't have
66+
access to that endpoint. I'm working on a way integrate with the getTeachers endpoint directly for the accounts that
67+
support it.
68+
69+
> [!CAUTION]
70+
> More documentation will follow soon.
71+
72+
Generating this mapping is rather tedious, but the first step is getting the IDs.
73+
See [2.1 Generating element IDs](#21-generating-element-ids) for help.
74+
75+
Example `subject_to_color`
76+
```python
77+
untis.my_config.timetable_mapping_config.subject_to_color: dict[tuple[str, str, int], tuple[int, int, int]] = {
78+
# Subjet abbreviation, full subject name, subject id: RGB Value
79+
('M', 'Math', 107): (83, 103, 220),
80+
('E', 'English', 193): (45, 26, 136),
81+
('FR', 'French', 981): (122, 112, 212)
82+
}
83+
```
84+
This allows the TimeTable to display corresponding colours along with the subject names.
85+
The API technically delivers this, but I'm still uncertain whether this is safe to use.
86+
87+
Generating this mapping is rather tedious, but the first step is getting the IDs.
88+
See [2.1 Generating element IDs](#21-generating-element-ids) for help.
89+
90+
Also see [config.py](../untis/config.py) for more info on `TimeTableMappingConfig`.
1991

2092
### 2.1 Generating element IDs
2193

94+
In the following you will see the code I used to generate teacher & subject IDs.
95+
2296
```python
2397
import typing
2498
import uuid
@@ -60,7 +134,9 @@ def _return_data_whole_school_year(
60134
return result_table
61135

62136

63-
def return_all_subjects(session: untis.Session) -> tuple[list[untis.objects.Subject], dict[untis.objects.Subject, list[str]]]:
137+
def return_all_subjects(
138+
session: untis.Session
139+
) -> tuple[list[untis.objects.Subject], dict[untis.objects.Subject, list[str]]]:
64140
subjects: list[untis.objects.Subject] = []
65141
subject_info: dict[untis.objects.Subject, list[str]] = {}
66142

@@ -89,7 +165,9 @@ def return_all_subjects(session: untis.Session) -> tuple[list[untis.objects.Subj
89165
return subjects, subject_info
90166

91167

92-
def return_all_teacher_ids(session: untis.Session) -> tuple[list[untis.objects.Teacher], dict[untis.objects.Teacher, list[str]]]:
168+
def return_all_teacher_ids(
169+
session: untis.Session
170+
) -> tuple[list[untis.objects.Teacher], dict[untis.objects.Teacher, list[str]]]:
93171
teachers: list[untis.objects.Teacher] = []
94172
teacher_info: dict[untis.objects.Teacher, list[str]] = {}
95173

@@ -118,10 +196,40 @@ def return_all_teacher_ids(session: untis.Session) -> tuple[list[untis.objects.T
118196
return teachers, teacher_info
119197
```
120198

199+
In this section, `Teacher` and `Subject` is interchangeable. Use `return_all_subjects` for receiving `Subject`s,
200+
and `return_all_teacher_ids` for `Teacher`s. The concept is the same for both.
201+
202+
These functions will return a `tuple[list[untis.objects.Teacher], dict[untis.objects.Teacher, list[str]]]`:
203+
- First element: `teachers: list[Teacher]`, the `name` and `long_name` fields will be set to `unknown` initially.
204+
205+
- Second element: `teacher_info: dict[untis.objects.Teacher, list[str]]`, this will help you fill up the teacher
206+
mapping. Each teacher will have a few lessons associated with it, so you can create the mapping `ID -> name`.
207+
In the Untis app the names of the teachers will be displayed, so open the Untis app and manually find the lessons
208+
and transfer the names of the teachers. I am aware that this is very tedious to do, especially if your school has
209+
hundreds of teachers.
210+
211+
> [!CAUTION]
212+
> More documentation will follow soon.
213+
121214
## 3. Language specific configuration
122215

123-
See [config.py](../untis/config.py) for more info.
216+
Also see [Setting the language](#11-setting-the-language) for more info on setting the language.
217+
218+
You can also manipulate values manually, for example:
219+
- `untis.my_config.language_config.two_week_abbreviation = ...`
220+
- `untis.my_config.language_config.two_week_abbreviation = ...`
221+
- ...
222+
223+
Also see [config.py](../untis/config.py) for more info on `LanguageConfig`.
124224

125225
## 4. HTML style configuration
126226

127-
See [config.py](../untis/config.py) for more info.
227+
Also see [Setting the language](#11-setting-the-language) for more info on setting the language.
228+
229+
You can also manipulate values manually, for example:
230+
- `my_config.html_style_config.timetable_html_footer = ...`
231+
- `my_config.html_style_config.html_style_config.lesson_time_ranges = ...`
232+
- `my_config.html_style_config.html_style_config.table_header_base_rgb = ...`
233+
- ...
234+
235+
Also see [config.py](../untis/config.py) for more info on `HTMLStyleConfig`.

examples/html_timetable.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
from credentials import global_session
33
import datetime
44

5-
call_id = global_session.get_unique_uuid()
6-
global_session.log_in(call_id)
7-
8-
klasse = global_session.get_klasse_by_name('1a') # Try '1A' alternatively
5+
untis.my_config.set_lang('en')
96

107
untis.my_config.timetable_html_footer = f"""
118
<p style="text-align:center; font-size:20px; margin-top:10px;">
129
powered by: This is how to edit `my_config`!
1310
</p>
1411
"""
1512

13+
call_id = global_session.get_unique_uuid()
14+
global_session.log_in(call_id)
15+
16+
klasse = global_session.get_klasse_by_name('1a') # Try '1A' alternatively
17+
18+
1619
today = datetime.date.today()
1720
monday = today - datetime.timedelta(days=today.weekday())
1821
friday = monday + datetime.timedelta(days=4)

0 commit comments

Comments
 (0)