Archive page #17

Merged
hugo merged 6 commits from hugo/website2:archive_page into master 2023-08-30 11:20:28 +00:00
5 changed files with 137 additions and 107 deletions
Showing only changes of commit 44910c183b - Show all commits

View File

@ -5,6 +5,7 @@ PAGES = [
{'name': 'account', 'titleSR': 'Nalog', 'titleEN': 'Account', 'style': 'account'}, {'name': 'account', 'titleSR': 'Nalog', 'titleEN': 'Account', 'style': 'account'},
{'name': 'contact', 'titleSR': 'Kontakt', 'titleEN': 'Contact', 'style': 'contact'}, {'name': 'contact', 'titleSR': 'Kontakt', 'titleEN': 'Contact', 'style': 'contact'},
{'name': 'events', 'titleSR': 'Događaji', 'titleEN': 'Events', 'style': 'events'}, {'name': 'events', 'titleSR': 'Događaji', 'titleEN': 'Events', 'style': 'events'},
{'name': 'events_archive', 'titleSR': 'Arhiva događaja', 'titleEN': 'Events archive', 'style': 'events'},
{'name': 'services', 'titleSR': 'Servisi', 'titleEN': 'Services', 'style': 'services'}, {'name': 'services', 'titleSR': 'Servisi', 'titleEN': 'Services', 'style': 'services'},
{'name': 'webring', 'titleSR': 'Webring', 'titleEN': 'Webring', 'style': ''}, {'name': 'webring', 'titleSR': 'Webring', 'titleEN': 'Webring', 'style': ''},
] ]

View File

@ -1,2 +1,2 @@
<h1>Events archive</h1> <h1>Events archive</h1>
<p>All events that we organized so far.</p> <p>All events that we organized so far.</p><br>

View File

@ -1,2 +1,2 @@
<h1>Arhiva događaja</h1> <h1>Arhiva događaja</h1>
<p>Svi događaji koje smo do sada organzivali.</p> <p>Svi događaji koje smo do sada organzivali.</p><br>

152
prep.py
View File

@ -1,92 +1,88 @@
#! /usr/bin/env python #! /usr/bin/env python
import csv
from datetime import datetime from datetime import datetime
from functools import cmp_to_key
DAYS_SR = ["Ponedeljak", "Utorak", "Sreda", "Četvrtak", "Petak", "Subota", "Nedelja"] DAYS_SR = ["PON", "UTO", "SRE", "ČET", "PET", "SUB", "NED"]
DAYS_EN = ["Monday ", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] DAYS_EN = ["MON ", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
MONTHS_SR = [
"Januar", "Februar", "Mart", "April", "Maj", "Jun", def load_events(csv_path:str) -> list[dict]:
"Jul", "Avgust", "Septembar", "Oktobar", "Novembar", "Decembar", events = []
] with open(csv_path) as csv_file:
MONTHS_EN = [ csv_reader = csv.reader(csv_file)
"January", "February", "March", "April", "May", "June", next(csv_reader, None)
"July", "August", "September", "October", "November", "December", for event in csv_reader:
] event_date = event[0]
event_date_parsed = datetime.strptime(event_date, "%d-%m-%Y").date()
event_time = event[1]
event_location = event[2]
event_title = event[3]
current_event = {"date":event_date_parsed,
"time":event_time,
"location": event_location,
"title":event_title.strip()}
events.append(current_event)
return events
def build_html(events: list[dict], dayNames: list[str]) -> str:
events_html = []
for event in events:
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"
event_html = []
event_html.append(f"<div class='date'>{date} {time}</div>")
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}\">@{place.strip()}</a></div>")
else:
event_html.append(f"<div class='place'>@{location.strip()}</div>")
event_html = "".join(event_html)
events_html.append(f"\n<div class='event'>{event_html}</div>")
return events_html
events = sorted(load_events("dogadjaji.csv"), key=lambda e: e["date"])
today = datetime.today().date() today = datetime.today().date()
def parse_date(date): past_events = list(filter(lambda e: e["date"] <= today, events))
return datetime.strptime(date,"%d-%m-%Y").date() new_events = list(filter(lambda e: e["date"] >= today, events))
def compare_events(one, two):
one = parse_date(one.split(", ")[0])
two = parse_date(two.split(", ")[0])
if one>two:
return 1
elif one==two:
return 0
else:
return -1
def is_past_event(event):
return event < today
def load_events():
events = []
with open("dogadjaji.csv", "rt") as file:
file.readline()
for event in file.readlines():
event = event.strip()
if event != "":
events.append(event)
return events
def write_events(events):
with open("dogadjaji.csv", "wt") as file:
file.write("datum, vreme, lokacija, tema\n")
for event in events:
file.write(event+"\n")
def sort_events(events):
return sorted(events, key = cmp_to_key(compare_events))
def build_html(events, dayNames, monthNames): page_template = ""
newevents = []
for event in events:
date, time, location, title = event.split(", ")
date = parse_date(date)
if is_past_event(date):
continue
date = dayNames[date.weekday()]+", "+str(date.day)+". "+monthNames[date.month-1]+" "+str(date.year)+"."
time = time+"h"
future_event = []
future_event.append("<td> "+date+" </td>")
future_event.append("<td> "+time+" </td>")
if "https://" in location:
place,link = location.split("https://")
future_event.append("<td> <a href=\"https://"+link+"\""+"> "+place.strip()+" </a> </td>")
else:
future_event.append("<td> "+location.strip()+" </td>")
future_event.append("<td> "+title+" </td>")
newevents.append("<tr>\n"+"\n".join(future_event)+"\n</tr>")
return newevents
events = load_events() # Build Serbian Events page
events = sort_events(events) new_events_html = build_html(new_events, DAYS_SR)
write_events(events) with open("pages/sr/events.html", "r") as file:
page_template = ([line for line in file])[:2]
newevents = build_html(events, DAYS_SR, MONTHS_SR) with open("pages/sr/events.html", "w") as file:
file.writelines(page_template + new_events_html)
with open("pages/sr/events.html","wt") as file: # Build English Events page
file.writelines(["<h1>Događaji</h1>\n", "<table>\n", "<tr><th>Datum</th><th>Vreme</th><th>Mesto</th><th>Tema</th></tr>\n"]) new_events_html = build_html(new_events, DAYS_EN)
file.writelines(newevents) with open("pages/en/events.html", "r") as file:
file.writelines(["</table>"]) page_template = ([line for line in file])[:2]
newevents = build_html(events, DAYS_EN, MONTHS_EN) with open("pages/en/events.html", "w") as file:
file.writelines(page_template + new_events_html)
with open("pages/en/events.html","wt") as file: # Build Serbian Archive page
file.writelines(["<h1>Events</h1>\n", "<table>\n", "<tr><th>Date</th><th>Time</th><th>Place</th><th>Topic</th></tr>"]) past_events_html = build_html(past_events, DAYS_SR)
file.writelines(newevents) with open("pages/sr/events_archive.html", "r") as file:
file.writelines(["</table>"]) page_template = ([line for line in file])[:2]
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)
with open("pages/en/events_archive.html", "r") as file:
page_template = ([line for line in file])[:2]
with open("pages/en/events_archive.html", "w") as file:
file.writelines(page_template + past_events_html)

View File

@ -1,30 +1,63 @@
table {
table-layout: fixed;
border-spacing: 0;
}
th,
td {
padding: 0 1rem 0 1rem;
text-align: left;
border-left: 2px solid var(--border);
}
th {
padding: 1rem 1rem 0 1rem;
border-bottom: 2px solid var(--border);
}
td:nth-child(odd) {
white-space: nowrap;
}
td {
padding: 0 1rem 1rem 1rem;
vertical-align: top;
}
h1 { h1 {
margin-bottom: 2rem; margin-bottom: 2rem;
font-weight: normal; font-weight: normal;
} }
.event {
display: flex;
flex-direction: row;
}
.event:hover {
border-bottom: 5px var(--hightlight) solid;
}
.event:hover>div {
padding-bottom: calc(0.5rem - 5px);
}
.event>div {
padding: 0.5rem;
white-space: nowrap;
}
.date {
width: 250px;
font-size: 0.9em;
overflow-x: hidden;
white-space: nowrap;
}
.title {
border-left: 2px solid var(--border);
font-weight: bold;
}
.place {
font-size: 0.9em;
}
@media screen and (max-width: 1160px) {
.event {
flex-direction: column;
margin-bottom: 1rem;
border-left: 2px solid var(--border);
}
.event > div {
padding: 0 0.5rem;
white-space: normal;
}
.event:hover {
border-bottom: none;
}
.event:hover> div {
padding-bottom: 0;
}
.title {
border-left: none;
}
}