some more error handling when parsing lectures for their title / date

This commit is contained in:
Maximilian Keßler 2021-09-17 10:43:14 +02:00
parent 602f6e4323
commit 10a8a42b84

View file

@ -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)
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)