forked from Decentrala/website
[Lint] ran formated
This commit is contained in:
@@ -25,9 +25,10 @@ TYPES_DICT = {
|
||||
"party": ("zabava", "entertainment"),
|
||||
}
|
||||
|
||||
def load_events(csv_path:str) -> list[dict]:
|
||||
|
||||
def load_events(csv_path: str) -> list[dict]:
|
||||
events = []
|
||||
with open(csv_path, encoding='utf-8') as csv_file:
|
||||
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["datum"]
|
||||
@@ -35,14 +36,16 @@ def load_events(csv_path:str) -> list[dict]:
|
||||
event_time = event["vreme"]
|
||||
event_location = event["lokacija"]
|
||||
event_title = event["tema"]
|
||||
types = event["tip"].split()
|
||||
types = event["tip"].split()
|
||||
link = event.get("link", "")
|
||||
current_event = {"date":event_date_parsed,
|
||||
"time":event_time,
|
||||
"location": event_location,
|
||||
"title":event_title.strip(),
|
||||
"types": types,
|
||||
"link": link}
|
||||
current_event = {
|
||||
"date": event_date_parsed,
|
||||
"time": event_time,
|
||||
"location": event_location,
|
||||
"title": event_title.strip(),
|
||||
"types": types,
|
||||
"link": link,
|
||||
}
|
||||
events.append(current_event)
|
||||
return events
|
||||
|
||||
@@ -53,17 +56,30 @@ def build_html(events: list[dict], dayNames: list[str], typesNames: dict) -> str
|
||||
title = event["title"]
|
||||
location = event["location"]
|
||||
date = event["date"]
|
||||
date = dayNames[date.weekday()]+", "+str(date.day)+". "+str(date.month)+". "+str(date.year)+", "
|
||||
time = event["time"]+"h"
|
||||
date = (
|
||||
dayNames[date.weekday()]
|
||||
+ ", "
|
||||
+ str(date.day)
|
||||
+ ". "
|
||||
+ str(date.month)
|
||||
+ ". "
|
||||
+ str(date.year)
|
||||
+ ", "
|
||||
)
|
||||
time = event["time"] + "h"
|
||||
event_html = []
|
||||
event_html.append(f"<div class='date'>{date} {time}</div>")
|
||||
if event["link"] != "":
|
||||
event_html.append(f"<div class='title'><a href=\"{event['link']}\">{title}</a></div>")
|
||||
event_html.append(
|
||||
f"<div class='title'><a href=\"{event['link']}\">{title}</a></div>"
|
||||
)
|
||||
else:
|
||||
event_html.append(f"<div class='title'>{title}</div>")
|
||||
if "https://" in location:
|
||||
place,link = location.split("https://")
|
||||
event_html.append(f"<div class='place'><a href=\"https://{link}\" target='_blank'>@{place.strip()}</a></div>")
|
||||
place, link = location.split("https://")
|
||||
event_html.append(
|
||||
f"<div class='place'><a href=\"https://{link}\" target='_blank'>@{place.strip()}</a></div>"
|
||||
)
|
||||
else:
|
||||
event_html.append(f"<div class='place'>@{location.strip()}</div>")
|
||||
|
||||
@@ -74,7 +90,7 @@ def build_html(events: list[dict], dayNames: list[str], typesNames: dict) -> str
|
||||
if typesNames.get(t) is not None:
|
||||
types_list += typesNames.get(t)
|
||||
if t != last_item:
|
||||
types_list += ', '
|
||||
types_list += ", "
|
||||
else:
|
||||
print(f"Unknown type {t}!")
|
||||
types_list += "</div>"
|
||||
@@ -84,6 +100,7 @@ def build_html(events: list[dict], dayNames: list[str], typesNames: dict) -> str
|
||||
events_html.append(f"\n<div class='event'>{event_html}</div>")
|
||||
return events_html
|
||||
|
||||
|
||||
def build_ical(events: list[dict]) -> str:
|
||||
today = datetime.today().now()
|
||||
# Header
|
||||
@@ -99,8 +116,17 @@ def build_ical(events: list[dict]) -> str:
|
||||
url = event["link"]
|
||||
|
||||
uid = str(date.month).zfill(2) + str(date.day).zfill(2) + time[:2]
|
||||
date = str(date.year) + str(date.month).zfill(2) + str(date.day).zfill(2)
|
||||
created = str(today.year) + str(today.month).zfill(2) + str(today.day).zfill(2) + "T" + str(today.hour).zfill(2) + str(today.minute).zfill(2) + str(today.second).zfill(2) + "Z"
|
||||
date = str(date.year) + str(date.month).zfill(2) + str(date.day).zfill(2)
|
||||
created = (
|
||||
str(today.year)
|
||||
+ str(today.month).zfill(2)
|
||||
+ str(today.day).zfill(2)
|
||||
+ "T"
|
||||
+ str(today.hour).zfill(2)
|
||||
+ str(today.minute).zfill(2)
|
||||
+ str(today.second).zfill(2)
|
||||
+ "Z"
|
||||
)
|
||||
date = date + "T" + time.replace(":", "") + "00"
|
||||
|
||||
event_template = ""
|
||||
@@ -118,20 +144,20 @@ def build_ical(events: list[dict]) -> str:
|
||||
break
|
||||
event_template = event_template.replace("<!--LOCATION-->", ical_location)
|
||||
|
||||
|
||||
events_ical += event_template
|
||||
# Footer
|
||||
with open("template/end.ical", "r") as file:
|
||||
events_ical += file.read()
|
||||
return events_ical
|
||||
|
||||
|
||||
events = sorted(load_events("dogadjaji.csv"), key=lambda e: e["date"])
|
||||
|
||||
today = datetime.today().date()
|
||||
|
||||
past_events = list(filter(lambda e: e["date"] <= today, events))
|
||||
past_events.reverse()
|
||||
new_events = list(filter(lambda e: e["date"] >= today, events))
|
||||
new_events = list(filter(lambda e: e["date"] >= today, events))
|
||||
|
||||
|
||||
page_template = ""
|
||||
@@ -146,7 +172,7 @@ for key, value_pair in TYPES_DICT.items():
|
||||
# Build Serbian Events page
|
||||
new_events_html = build_html(new_events, DAYS_SR, sr_types)
|
||||
with open("template/events-sr.html", "r") as file:
|
||||
page_template = ([line for line in file])
|
||||
page_template = [line for line in file]
|
||||
|
||||
with open("pages/sr/events.html", "w") as file:
|
||||
file.writelines(page_template + new_events_html)
|
||||
@@ -154,7 +180,7 @@ with open("pages/sr/events.html", "w") as file:
|
||||
# Build English Events page
|
||||
new_events_html = build_html(new_events, DAYS_EN, en_types)
|
||||
with open("template/events-en.html", "r") as file:
|
||||
page_template = ([line for line in file])
|
||||
page_template = [line for line in file]
|
||||
|
||||
with open("pages/en/events.html", "w") as file:
|
||||
file.writelines(page_template + new_events_html)
|
||||
@@ -162,7 +188,7 @@ with open("pages/en/events.html", "w") as file:
|
||||
# Build Serbian Archive page
|
||||
past_events_html = build_html(past_events, DAYS_SR, sr_types)
|
||||
with open("template/events_archive-sr.html", "r") as file:
|
||||
page_template = ([line for line in file])
|
||||
page_template = [line for line in file]
|
||||
|
||||
with open("pages/sr/events_archive.html", "w") as file:
|
||||
file.writelines(page_template + past_events_html)
|
||||
@@ -170,7 +196,7 @@ with open("pages/sr/events_archive.html", "w") as file:
|
||||
# Build English Archive page
|
||||
past_events_html = build_html(past_events, DAYS_EN, en_types)
|
||||
with open("template/events_archive-en.html", "r") as file:
|
||||
page_template = ([line for line in file])
|
||||
page_template = [line for line in file]
|
||||
|
||||
with open("pages/en/events_archive.html", "w") as file:
|
||||
file.writelines(page_template + past_events_html)
|
||||
@@ -180,4 +206,3 @@ new_events_ical = build_ical(new_events)
|
||||
# Build ical
|
||||
with open("site/events.ical", "w") as file:
|
||||
file.write(build_ical(new_events))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user