Export my schedule as an .ics file #30
Labels
No labels
bug
chore
data
feature
frontend
good first issue
intermediate
needs/docs
needs/research
needs/upstream
type/bug
type/external
type/feature
type/refactor
urgency
high
urgency
immediate
urgency
low
urgency
medium
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ScottyLabs/cal#30
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Many students live in Apple Calendar or Outlook. Add an "Export" button that downloads the current schedule as an
.icsfile they can import.What you'll learn
Generating a file in a Flask route with the
icalendarlibrary, and downloading a file in the browser.Resources
Where to start
api/app/api/schedule.py,get_schedule_route: already loads the caller's schedule (checking ownership), its orgs, and their occurrences. AddGET /api/schedule/export?schedule_id=next to it and reuse that query.icalendaris already a dependency (api/pyproject.toml).api/app/services/ical.pyuses it for importing.Calendarwith oneVEVENTperEventOccurrence(UID,DTSTART,DTEND,SUMMARY,LOCATION,DESCRIPTION). Returncal.to_ical()withmimetype="text/calendar"andContent-Disposition: attachment; filename="cmucal.ics".web/src/app/components/ProfileSidebar.tsxor the schedule selector inNavbar.tsx: add the button.Done when
cmucal.icsfor the selected scheduleschedule_idreturns 404icalendar.Calendar.from_icaland checks the event countNotes
The API authenticates only with a bearer token, so a plain
<a href>to the API will get a 401. Fetch the file withapi.get(url, { responseType: "blob" }), make a URL withURL.createObjectURL, and click a temporary<a download>. Keep datetimes timezone-aware so the times do not shift.