|
| 1 | +import yaml |
| 2 | +import hashlib |
| 3 | +from datetime import datetime |
| 4 | +from icalendar import Calendar, Event |
| 5 | +import pytz |
| 6 | + |
| 7 | +# ---- SETTINGS ---- |
| 8 | +TIMEZONE = "Europe/Berlin" # Change to your time zone, e.g. "America/New_York" |
| 9 | + |
| 10 | +# Load YAML |
| 11 | +with open("_data/events.yml", "r") as f: |
| 12 | + data = yaml.safe_load(f) |
| 13 | + |
| 14 | +# Prepare calendar |
| 15 | +cal = Calendar() |
| 16 | +cal.add("prodid", "-//My GitHub Calendar//EN") |
| 17 | +cal.add("version", "2.0") |
| 18 | + |
| 19 | +tz = pytz.timezone(TIMEZONE) |
| 20 | + |
| 21 | +for ev in data: |
| 22 | + event = Event() |
| 23 | + |
| 24 | + # Parse date and assume meetup is from 18:00 to 20:00 |
| 25 | + event_date = datetime.strptime(ev["date"], "%Y-%m-%d") |
| 26 | + start_dt = tz.localize(event_date.replace(hour=18, minute=0)) |
| 27 | + end_dt = tz.localize(event_date.replace(hour=21, minute=0)) |
| 28 | + |
| 29 | + event.add("summary", ev["title"]) |
| 30 | + event.add("dtstart", start_dt) |
| 31 | + event.add("dtend", end_dt) |
| 32 | + |
| 33 | + # Add location information with enhanced mapping |
| 34 | + location = ev.get('host', 'TBA') |
| 35 | + if location and location.lower() != 'online': |
| 36 | + event.add("location", location) |
| 37 | + elif location and location.lower() == 'online': |
| 38 | + event.add("location", "Online Event") |
| 39 | + |
| 40 | + # Add the event link as URL |
| 41 | + if 'event_link' in ev: |
| 42 | + event.add("url", ev['event_link']) |
| 43 | + |
| 44 | + # Create description from talks if available |
| 45 | + description = f"Host: {ev.get('host', 'TBA')}\n" |
| 46 | + if 'talks' in ev and ev['talks']: |
| 47 | + description += "Talks:\n" |
| 48 | + for talk in ev['talks']: |
| 49 | + description += f"- {talk['title']} by {talk['speaker']}\n" |
| 50 | + if 'event_link' in ev: |
| 51 | + description += f"\nEvent link (RSVP): {ev['event_link']}" |
| 52 | + |
| 53 | + event.add("description", description) |
| 54 | + |
| 55 | + # Create stable UID by hashing title + date |
| 56 | + uid_base = f"{ev['id']}" |
| 57 | + uid_hash = hashlib.md5(uid_base.encode("utf-8")).hexdigest() |
| 58 | + event.add("uid", f"{uid_hash}@cncflinz.at") |
| 59 | + |
| 60 | + cal.add_component(event) |
| 61 | + |
| 62 | +# Save ICS |
| 63 | +with open("calendar.ics", "wb") as f: |
| 64 | + f.write(cal.to_ical()) |
0 commit comments