From 457f13ea55305a54a2b7dcad7ce4ed75a4f3037f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= Date: Wed, 6 Nov 2024 15:25:47 +0100 Subject: [PATCH] fetch: Fix case in which feed_info.txt exists but doesn't contain the required row --- src/fetch.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/fetch.py b/src/fetch.py index 3f644b01..83b9c48c 100755 --- a/src/fetch.py +++ b/src/fetch.py @@ -39,19 +39,24 @@ def validate_source_name(name: str): def check_feed_timeframe_valid(zip_content: bytes): with ZipFile(file=io.BytesIO(zip_content)) as z: - if "feed_info.txt" in z.namelist(): - with z.open("feed_info.txt", "r") as a: - with io.TextIOWrapper(a) as at: - feedinforeader = csv.DictReader(at, delimiter=",", - quotechar='"') - for row in feedinforeader: - start_date = \ - datetime.strptime(row["feed_start_date"], - "%Y%m%d") - - today = datetime.today() - if start_date > today: - return False + if "feed_info.txt" not in z.namelist(): + return True + + with z.open("feed_info.txt", "r") as a: + with io.TextIOWrapper(a) as at: + feedinforeader = csv.DictReader(at, delimiter=",", + quotechar='"') + for row in feedinforeader: + if "feed_start_date" not in row: + return True + + start_date = \ + datetime.strptime(row["feed_start_date"], + "%Y%m%d") + + today = datetime.today() + if start_date > today: + return False return True