Add event types
This commit is contained in:
43
prep.py
43
prep.py
@@ -5,6 +5,15 @@ from datetime import datetime
|
||||
|
||||
DAYS_SR = ["PON", "UTO", "SRE", "ČET", "PET", "SUB", "NED"]
|
||||
DAYS_EN = ["MON ", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
|
||||
TYPES_DICT = {
|
||||
"hack": ("hakaton", "hackathon"),
|
||||
"lecture": ("predavanje", "lecture"),
|
||||
"workshop": ("radionioca", "workshop"),
|
||||
"discussion": ("diskusija", "discussion"),
|
||||
"lighting": ("kratka predavanja", "short talks"),
|
||||
"movie": ("film", "movie"),
|
||||
"meeting": ("sastanak", "meeting"),
|
||||
}
|
||||
|
||||
def load_events(csv_path:str) -> list[dict]:
|
||||
events = []
|
||||
@@ -17,14 +26,16 @@ def load_events(csv_path:str) -> list[dict]:
|
||||
event_time = event[1]
|
||||
event_location = event[2]
|
||||
event_title = event[3]
|
||||
types = event[4].split()
|
||||
current_event = {"date":event_date_parsed,
|
||||
"time":event_time,
|
||||
"location": event_location,
|
||||
"title":event_title.strip()}
|
||||
"title":event_title.strip(),
|
||||
"types": types }
|
||||
events.append(current_event)
|
||||
return events
|
||||
|
||||
def build_html(events: list[dict], dayNames: list[str]) -> str:
|
||||
def build_html(events: list[dict], dayNames: list[str], typesNames: dict) -> str:
|
||||
events_html = []
|
||||
for event in events:
|
||||
title = event["title"]
|
||||
@@ -41,6 +52,19 @@ def build_html(events: list[dict], dayNames: list[str]) -> str:
|
||||
else:
|
||||
event_html.append(f"<div class='place'>@{location.strip()}</div>")
|
||||
|
||||
if len(event["types"]) != 0:
|
||||
types_list = "<div class='types'>"
|
||||
last_item = event["types"][-1]
|
||||
for t in event["types"]:
|
||||
if typesNames.get(t) is not None:
|
||||
types_list += typesNames.get(t)
|
||||
if t != last_item:
|
||||
types_list += ', '
|
||||
else:
|
||||
print(f"Unknown type {t}!")
|
||||
types_list += "</div>"
|
||||
event_html.append(types_list)
|
||||
|
||||
event_html = "".join(event_html)
|
||||
events_html.append(f"\n<div class='event'>{event_html}</div>")
|
||||
return events_html
|
||||
@@ -88,8 +112,15 @@ new_events = list(filter(lambda e: e["date"] >= today, events))
|
||||
|
||||
page_template = ""
|
||||
|
||||
sr_types = {}
|
||||
en_types = {}
|
||||
|
||||
for key, value_pair in TYPES_DICT.items():
|
||||
sr_types[key] = value_pair[0]
|
||||
en_types[key] = value_pair[1]
|
||||
|
||||
# Build Serbian Events page
|
||||
new_events_html = build_html(new_events, DAYS_SR)
|
||||
new_events_html = build_html(new_events, DAYS_SR, sr_types)
|
||||
with open("pages/sr/events.html", "r") as file:
|
||||
page_template = ([line for line in file])
|
||||
|
||||
@@ -97,7 +128,7 @@ with open("pages/sr/events.html", "w") as file:
|
||||
file.writelines(page_template + new_events_html)
|
||||
|
||||
# Build English Events page
|
||||
new_events_html = build_html(new_events, DAYS_EN)
|
||||
new_events_html = build_html(new_events, DAYS_EN, en_types)
|
||||
with open("pages/en/events.html", "r") as file:
|
||||
page_template = ([line for line in file])
|
||||
|
||||
@@ -105,7 +136,7 @@ with open("pages/en/events.html", "w") as file:
|
||||
file.writelines(page_template + new_events_html)
|
||||
|
||||
# Build Serbian Archive page
|
||||
past_events_html = build_html(past_events, DAYS_SR)
|
||||
past_events_html = build_html(past_events, DAYS_SR, sr_types)
|
||||
with open("pages/sr/events_archive.html", "r") as file:
|
||||
page_template = ([line for line in file])
|
||||
|
||||
@@ -113,7 +144,7 @@ with open("pages/sr/events_archive.html", "w") as file:
|
||||
file.writelines(page_template + past_events_html)
|
||||
|
||||
# Build English Archive page
|
||||
past_events_html = build_html(past_events, DAYS_EN)
|
||||
past_events_html = build_html(past_events, DAYS_EN, en_types)
|
||||
with open("pages/en/events_archive.html", "r") as file:
|
||||
page_template = ([line for line in file])
|
||||
|
||||
|
Reference in New Issue
Block a user