[CSV] parsing csv with DictReader instead

This commit is contained in:
coja
2026-05-02 04:00:17 +02:00
parent 749574c8dc
commit 02c2dcc9fc

21
prep.py
View File

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