From 02c2dcc9fc34d26d6c13f093c164ff1a0b090dbf Mon Sep 17 00:00:00 2001 From: coja Date: Sat, 2 May 2026 04:00:17 +0200 Subject: [PATCH] [CSV] parsing csv with DictReader instead --- prep.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/prep.py b/prep.py index 0a7a357..2171a92 100755 --- a/prep.py +++ b/prep.py @@ -20,20 +20,16 @@ TYPES_DICT = { def load_events(csv_path:str) -> list[dict]: events = [] - with open(csv_path) as csv_file: - csv_reader = csv.reader(csv_file, skipinitialspace=True) - next(csv_reader, None) + with open(csv_path, encoding='utf-8') as csv_file: + csv_reader = csv.DictReader(csv_file, skipinitialspace=True) for event in csv_reader: - event_date = event[0] + event_date = event["datum"] event_date_parsed = datetime.strptime(event_date, "%d-%m-%Y").date() - event_time = event[1] - event_location = event[2] - event_title = event[3] - types = event[4].split() - try: - link = event[5] - except IndexError: - link = "" + event_time = event["vreme"] + event_location = event["lokacija"] + event_title = event["tema"] + types = event["tip"].split() + link = event.get("link", "") current_event = {"date":event_date_parsed, "time":event_time, "location": event_location, @@ -43,6 +39,7 @@ def load_events(csv_path:str) -> list[dict]: events.append(current_event) return events + def build_html(events: list[dict], dayNames: list[str], typesNames: dict) -> str: events_html = [] for event in events: