Fix events script

This commit is contained in:
Hugo 2023-08-29 13:58:50 +02:00
parent d31e4e10c8
commit 1f5e541922
2 changed files with 41 additions and 105 deletions

View File

@ -1,59 +1 @@
<h1>Događaji</h1>
<table>
<tbody>
<tr>
<th>Datum</th>
<th>Vreme</th>
<th>Mesto</th>
<th>Tema</th>
</tr>
<tr>
<td> Ponedeljak, 7. Avgust 2023. </td>
<td> 19:00h </td>
<td> DC Krov </td>
<td> Linux ricing </td>
</tr>
<tr>
<td> Utorak, 8. Avgust 2023. </td>
<td> 19:00h </td>
<td> DC Krov </td>
<td> Lambda račun </td>
</tr>
<tr>
<td> Ponedeljak, 14. Avgust 2023. </td>
<td> 19:00h </td>
<td> DC Krov </td>
<td> Linux distro diskusija </td>
</tr>
<tr>
<td> Utorak, 15. Avgust 2023. </td>
<td> 19:00h </td>
<td> DC Krov </td>
<td> Pirati 777 mora </td>
</tr>
<tr>
<td> Ponedeljak, 21. Avgust 2023. </td>
<td> 19:00h </td>
<td> DC Krov </td>
<td> Python vežbe </td>
</tr>
<tr>
<td> Utorak, 22. Avgust 2023. </td>
<td> 19:00h </td>
<td> DC Krov </td>
<td> Autentifikacija na internetu </td>
</tr>
<tr>
<td> Ponedeljak, 28. Avgust 2023. </td>
<td> 19:00h </td>
<td> DC Krov </td>
<td> Podešvanje Mail servera </td>
</tr>
<tr>
<td> Utorak, 29. Avgust 2023. </td>
<td> 19:00h </td>
<td> DC Krov </td>
<td> Prevođenje wiki-ja </td>
</tr>
</tbody>
</table>
<h1>Događaji</h1>

86
prep.py
View File

@ -3,30 +3,16 @@
from datetime import datetime
from functools import cmp_to_key
days = [
"Ponedeljak",
"Utorak",
"Sreda",
"Četvrtak",
"Petak",
"Subota",
"Nedelja",
]
months = [
"Januar",
"Februar",
"Mart",
"April",
"Maj",
"Jun",
"Jul",
"Avgust",
"Septembar",
"Oktobar",
"Novembar",
"Decembar",
]
DAYS_SR = ["Ponedeljak", "Utorak", "Sreda", "Četvrtak", "Petak", "Subota", "Nedelja"]
DAYS_EN = ["Monday ", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
MONTHS_SR = [
"Januar", "Februar", "Mart", "April", "Maj", "Jun",
"Jul", "Avgust", "Septembar", "Oktobar", "Novembar", "Decembar",
]
MONTHS_EN = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December",
]
today = datetime.today().date()
@ -66,36 +52,44 @@ def sort_events(events):
return sorted(events, key = cmp_to_key(compare_events))
def build_html(events, dayNames, monthNames):
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()
events = sort_events(events)
write_events(events)
newevents = []
print(events)
for event in events:
date, time, location, title = event.split(", ")
date = parse_date(date)
if is_past_event(date):
continue
date = days[date.weekday()]+", "+str(date.day)+". "+months[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>")
newevents = build_html(events, DAYS_SR, MONTHS_SR)
print(newevents)
with open("pages/sr/events.html","wt") as file:
file.writelines(["<h1>Događaji</h1>\n", "<table>\n", "<tr><th>Datum</th><th>Vreme</th><th>Mesto</th><th>Tema</th></tr>\n"])
file.writelines(newevents)
file.writelines(["</table>"])
#with open("pages/en/events.html","wt") as file:
# file.writelines(["<h1>Events</h1>", "<table>", "<tr>\n<th>Date</th>\n<th>Time</th>\n<th>Place</th>\n<th>Theme</th>\n</tr>"])
# file.writelines(events)
# file.writelines(["</table>"])
newevents = build_html(events, DAYS_EN, MONTHS_EN)
with open("pages/en/events.html","wt") as file:
file.writelines(["<h1>Events</h1>\n", "<table>\n", "<tr><th>Date</th><th>Time</th><th>Place</th><th>Topic</th></tr>"])
file.writelines(newevents)
file.writelines(["</table>"])