From 10a8a42b84b3f34df5e3c685081ff26cd1e8b0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 17 Sep 2021 10:43:14 +0200 Subject: [PATCH] some more error handling when parsing lectures for their title / date --- scripts/lectures.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/lectures.py b/scripts/lectures.py index 5801e04..a64bc46 100644 --- a/scripts/lectures.py +++ b/scripts/lectures.py @@ -2,7 +2,7 @@ import locale import os import re -import subprocess +import warnings from datetime import datetime from config import DATE_FORMAT, LOCALE, DEFAULT_NEW_LECTURE_HEADER, DEFAULT_LECTURE_SEARCH_REGEX @@ -29,10 +29,14 @@ class Lecture: if lecture_match: break - # number = int(lecture_match.group(1)) if lecture_match: date_str = lecture_match.group(2) - date = datetime.strptime(date_str, DATE_FORMAT) + try: + date = datetime.strptime(date_str, DATE_FORMAT) + except ValueError: + warnings.warn(f"Invalid date format found in lecture file {file_path}. Specify time in format" + f"'{DATE_FORMAT}' that you set in the config.py file.") + date = datetime.min week = get_week(date) title = lecture_match.group(3)