first commit
This commit is contained in:
commit
34ea15a54d
246 changed files with 18660 additions and 0 deletions
38
backend/app/services/calendar.py
Normal file
38
backend/app/services/calendar.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from app.models import EventEdition
|
||||
|
||||
|
||||
def _fmt_ics(dt: datetime) -> str:
|
||||
if dt.tzinfo is None:
|
||||
dt = dt.replace(tzinfo=timezone.utc)
|
||||
return dt.strftime("%Y%m%dT%H%M%SZ")
|
||||
|
||||
|
||||
def build_ics(edition: EventEdition, page_url: str) -> str:
|
||||
start = edition.event_date or datetime.now(timezone.utc) + timedelta(days=7)
|
||||
end = start + timedelta(hours=4)
|
||||
uid = f"desi-clans-{edition.slug}@bengaluru"
|
||||
location = edition.venue_name or edition.city
|
||||
summary = edition.title.replace(",", "\\,")
|
||||
desc = (edition.meta_description or edition.description or edition.title).replace("\n", "\\n")
|
||||
|
||||
lines = [
|
||||
"BEGIN:VCALENDAR",
|
||||
"VERSION:2.0",
|
||||
"PRODID:-//Desi Clans//Bengaluru Events//EN",
|
||||
"CALSCALE:GREGORIAN",
|
||||
"METHOD:PUBLISH",
|
||||
"BEGIN:VEVENT",
|
||||
f"UID:{uid}",
|
||||
f"DTSTAMP:{_fmt_ics(datetime.now(timezone.utc))}",
|
||||
f"DTSTART:{_fmt_ics(start)}",
|
||||
f"DTEND:{_fmt_ics(end)}",
|
||||
f"SUMMARY:{summary}",
|
||||
f"DESCRIPTION:{desc} — {page_url}",
|
||||
f"LOCATION:{location}",
|
||||
f"URL:{page_url}",
|
||||
"END:VEVENT",
|
||||
"END:VCALENDAR",
|
||||
]
|
||||
return "\r\n".join(lines) + "\r\n"
|
||||
Loading…
Add table
Add a link
Reference in a new issue