-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathgenerate_calendar.py
More file actions
83 lines (67 loc) · 2.8 KB
/
generate_calendar.py
File metadata and controls
83 lines (67 loc) · 2.8 KB
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
75
76
77
78
79
80
81
82
83
import yaml
import hashlib
from datetime import datetime
from icalendar import Calendar, Event
import pytz
# ---- SETTINGS ----
TIMEZONE = "Europe/Berlin" # Change to your time zone, e.g. "America/New_York"
CALENDAR_NAME = "Cloud Native Linz Events"
CALENDAR_DESCRIPTION = "Meetup events for the Cloud Native Linz community"
# Load YAML
with open("_data/events.yml", "r") as f:
data = yaml.safe_load(f)
# Prepare calendar
cal = Calendar()
cal.add("prodid", "-//Cloud Native Linz Calendar//EN")
cal.add("version", "2.0")
cal.add("x-wr-calname", CALENDAR_NAME) # Calendar name (widely supported)
cal.add("x-wr-caldesc", CALENDAR_DESCRIPTION) # Calendar description
cal.add("name", CALENDAR_NAME) # Standard property for calendar name
tz = pytz.timezone(TIMEZONE)
for ev in data:
event = Event()
# Parse date
event_date = datetime.strptime(ev["date"], "%Y-%m-%d")
# Use doors_open time if available, otherwise default to 18:00 (6pm)
if 'doors_open' in ev and ev['doors_open']:
# Parse the doors_open time (format: 'HH:MM')
time_parts = ev['doors_open'].split(':')
start_hour = int(time_parts[0])
start_minute = int(time_parts[1])
else:
start_hour = 18
start_minute = 0
start_dt = tz.localize(event_date.replace(hour=start_hour, minute=start_minute))
# End time is 3 hours after start
end_dt = tz.localize(event_date.replace(hour=start_hour + 3, minute=start_minute))
# Append "CNCF Linz" to the event title
event_title = f"{ev['title']} - CNCF Linz"
event.add("summary", event_title)
event.add("dtstart", start_dt)
event.add("dtend", end_dt)
# Add location information - prefer address field if available, otherwise use host
location = ev.get('address') if 'address' in ev and ev['address'] else ev.get('host', 'TBA')
if location and location.lower() != 'online':
event.add("location", location)
elif location and location.lower() == 'online':
event.add("location", "Online Event")
# Add the event link as URL
if 'event_link' in ev:
event.add("url", ev['event_link'])
# Create description from talks if available
description = f"Host: {ev.get('host', 'TBA')}\n"
if 'talks' in ev and ev['talks']:
description += "Talks:\n"
for talk in ev['talks']:
description += f"- {talk['title']} by {talk['speaker']}\n"
if 'event_link' in ev:
description += f"\nEvent link (RSVP): {ev['event_link']}"
event.add("description", description)
# Create stable UID by hashing the event id
uid_base = f"{ev['id']}"
uid_hash = hashlib.sha256(uid_base.encode("utf-8")).hexdigest()
event.add("uid", f"{uid_hash}@cncflinz.at")
cal.add_component(event)
# Save ICS
with open("calendar.ics", "wb") as f:
f.write(cal.to_ical())