-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
74 lines (59 loc) · 2 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import datetime
import requests
import operator
import dataclasses as dt
from pathlib import Path
@dt.dataclass
class ScheduleEntry:
title: str
category: str
url: str
where: str
start: datetime.datetime
end: datetime.datetime
def grabIcal(year: str) -> str:
r = requests.get(f"https://fosdem.org/{year}/schedule/ical")
return r.text
def createSchedule(ical: str) -> list[ScheduleEntry]:
icalEntries = ical.split("\r\n\r\n")
schedule = []
for raw in icalEntries:
if "VEVENT" not in raw:
continue
data = dict([l.split(":", 1) for l in raw.splitlines()])
schedule.append(
ScheduleEntry(
title=data["SUMMARY"],
category=data["CATEGORIES"],
url=data["URL"].replace("https:/", "https://"),
where=data["LOCATION"],
start=datetime.datetime.strptime(data["DTSTART"], "%Y%m%dT%H%M%S"),
end=datetime.datetime.strptime(data["DTEND"], "%Y%m%dT%H%M%S"),
)
)
schedule.sort(key=operator.attrgetter("start"))
return schedule
def exportCsv(schedule: list[ScheduleEntry], file_output: Path, delimeter: str = "\t"):
with file_output.open("w") as csv:
csv.write(
delimeter.join(["Début", "Fin", "Track", "Summary", "Où", "Url"]) + "\n"
)
for entry in schedule:
csv.write(
delimeter.join(
[
entry.start.strftime("%A %H:%M"),
entry.end.strftime("%A %H:%M"),
entry.category,
entry.title,
entry.where,
entry.url,
]
)
+ "\n"
)
if __name__ == "__main__":
actualYear = datetime.datetime.now().year
ical = grabIcal(str(actualYear))
schedule = createSchedule(ical)
exportCsv(schedule, Path(__file__).parent / f"fosdem{actualYear}.csv")