From bba0994ffbce3016d4038504370a953812aefd15 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 5 Apr 2023 16:39:10 +0200 Subject: 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}'``` --- lessons.py | 12 +++++++++--- 1 file 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, -- cgit v1.2.3