aboutsummaryrefslogtreecommitdiff
path: root/lessons.py
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-04-05 16:39:10 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2023-04-05 16:39:10 +0200
commitbba0994ffbce3016d4038504370a953812aefd15 (patch)
tree1483c55729fd03f02eafc40a9fc8ac413299031f /lessons.py
parent6c9cbaf8aa1915dcb3158d8ae856dab0d15b19e6 (diff)
downloadavail-lessons-bba0994ffbce3016d4038504370a953812aefd15.tar.gz
avail-lessons-bba0994ffbce3016d4038504370a953812aefd15.zip
add line formatting for events
I want to color a table row in a certain color if a early end of class causes my lesson to be canceled. To do so I use the new configuration table: ```toml [event_line_formats] Unterrichtsschluss = '\\rowcolor{{red!30}} {line}'```
Diffstat (limited to 'lessons.py')
-rwxr-xr-xlessons.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/lessons.py b/lessons.py
index b29918d..10476c3 100755
--- a/lessons.py
+++ b/lessons.py
@@ -93,15 +93,21 @@ def format_period(period: webuntis.objects.PeriodObject,
# strip the leading ' ' and trailing ' |'
period_events = period_events[1:-2]
- output = config.get(
+ fmt = config.get(
'fmt') or '{week} {date.strftime(\'%d.%m\')} {period_events}'
# Using eval here instead of string.format() is potentially dangerous.
# However, I do not consider this an actual thread because this is an
# obscure script run with only trusted inputs (cli arguments, manual written
# config), therefore potential code execution is not a real concern.
- output = eval(F'f"{output}"') # pylint: disable=eval-used
+ line = eval('f' + f'"{fmt}"') # pylint: disable=eval-used
- return output
+ # Apply event_line_formats
+ event_line_formats = config.get('event_line_formats', [])
+ for ev in period_evs:
+ if ev.summary in event_line_formats:
+ line = eval('f' + f'"{event_line_formats[ev.summary]}"')
+
+ return line
def filter_periods(timetable: webuntis.objects.PeriodList,