aboutsummaryrefslogtreecommitdiff
path: root/lessons.py
diff options
context:
space:
mode:
Diffstat (limited to 'lessons.py')
-rwxr-xr-xlessons.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/lessons.py b/lessons.py
index ea17e06..75283ac 100755
--- a/lessons.py
+++ b/lessons.py
@@ -75,26 +75,29 @@ def load_events(config: dict) -> list[icalevents.icalparser.Event]:
def format_period(period: webuntis.objects.PeriodObject,
evs: list[icalevents.icalparser.Event], config: dict) -> str:
"""Format a given period"""
- # Provide some usefull shortcuts for the output format
- day = period.start.date()
- week = day.isocalendar().week # pylint: disable=unused-variable
-
- output = config.get('fmt') or '{week} {day.strftime(\'%d.%m\')}'
- # 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 wirtten
- # config), therefore potential code execution is not a real concern.
- output = eval(F'f"{output}"') # pylint: disable=eval-used
+ # Provide some useful shortcuts for the output format
+ date = period.start.date()
+ week = date.isocalendar().week # pylint: disable=unused-variable
+ period_events = ""
period_evs = [
ev for ev in evs if
ev.start.timestamp() <= period.start.timestamp() <= ev.end.timestamp()
]
if period_evs:
for event in period_evs:
- output += f' {event.summary} &'
+ period_events += f' {event.summary} &'
# strip the trailing ' &' suffix
- output = output[:-2]
+ period_events = period_events[:-2]
+
+ output = 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
+
return output
@@ -166,6 +169,9 @@ def main():
if args.show_events:
evs = load_events(config)
+ if 'output_header' in config:
+ print(config['output_header'])
+
for period in filter_periods(timetable, config):
if period.code:
print(f'WARNING: period {period.start} is {period.code}',