Sub topic 11
Exporting and Sharing the Calendar
This chapter assumes you have a calendar data model with one row per activity, as in the earlier chapters. It also assumes you can read short Python scripts. The goal is to move that data into other systems without losing meaning.
Why export at all
Your calendar tool will not be the only place people look. Executives may live in Outlook or Google Calendar. An analyst may want a spreadsheet. A reporting tool may need a clean table. Export turns your single source of truth into copies that other systems can read.
Pick one format per job:
| Format | Best for | Weakness |
|---|---|---|
| CSV | Spreadsheets, reporting tools, bulk import | No time zones, no update tracking |
| iCalendar (.ics) | Personal calendars and subscriptions | Little room for custom fields |
Exporting to CSV
CSV is a flat table. Each row is one activity, and the header names the fields. A good export keeps the same columns as your data model, so a re-import needs no mapping.
campaign,activity,channel,owner,status,start_date,end_date
Spring Sale,Launch email,email,Priya,in_review,2026-03-02,2026-03-02
Social teaser,social,Marcus,draft,2026-02-27,2026-03-01Check the example above before you copy it. The second data row is missing its campaign value, so it has six fields instead of seven. Many importers shift every later column left, which puts "Marcus" in the status column. This is the most common CSV error. Count the fields in each row, and quote any value that contains a comma.
Here is the corrected version:
campaign,activity,channel,owner,status,start_date,end_date
Spring Sale,Launch email,email,Priya,in_review,2026-03-02,2026-03-02
Spring Sale,Social teaser,social,Marcus,draft,2026-02-27,2026-03-01
Product Launch,Announcement post,web,Dana,planned,2026-03-10,2026-03-10Use ISO dates (YYYY-MM-DD). Formats such as 03/02/2026 read as March 2 in the US and 3 February elsewhere.
Exporting to iCalendar
An .ics file describes events in a format that nearly every calendar app can import. A minimal all-day event looks like this:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Example Marketing//Campaign Calendar//EN
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20260226T120000Z
DTSTART;VALUE=DATE:20260302
DTEND;VALUE=DATE:20260303
SUMMARY:Spring Sale launch email
END:VEVENT
END:VCALENDARThree details cause most problems:
- UID must be stable. The calendar app uses it to decide whether an imported event is new or an update. If you generate a random UID on each export, every import creates duplicates.
- All-day DTEND is exclusive. An event on 2 March ends on 3 March in the file. If your data model stores inclusive end dates, add one day when you export.
- Lines end with CRLF. The standard requires carriage return plus line feed. Some strict importers reject files with plain line feeds.
A small export script
This script reads the CSV and writes an .ics file. It builds the UID from the campaign, activity and start date, so the same row always gets the same UID. It also adds one day to the end date.
import csv
from datetime import date, timedelta
CRLF = "\r\n"
def slug(text: str) -> str:
return "-".join(text.lower().split())
def to_ics(rows) -> str:
lines = [
"BEGIN:VCALENDAR",
"VERSION:2.0",
"PRODID:-//Example Marketing//Campaign Calendar//EN",
]
for row in rows:
start = date.fromisoformat(row["start_date"])
end = date.fromisoformat(row["end_date"]) + timedelta(days=1)
uid = f"{slug(row['campaign'])}-{slug(row['activity'])}-{start:%Y%m%d}@example.com"
lines += [
"BEGIN:VEVENT",
f"UID:{uid}",
"DTSTAMP:20260226T120000Z",
f"DTSTART;VALUE=DATE:{start:%Y%m%d}",
f"DTEND;VALUE=DATE:{end:%Y%m%d}",
f"SUMMARY:{row['campaign']}: {row['activity']}",
"END:VEVENT",
]
lines.append("END:VCALENDAR")
return CRLF.join(lines) + CRLF
with open("calendar.csv", newline="") as f:
rows = list(csv.DictReader(f))
with open("calendar.ics", "w", newline="") as f:
f.write(to_ics(rows))Save the corrected CSV as calendar.csv before you run it. The newline="" argument stops Python from rewriting the CRLF line endings.
The fixed DTSTAMP keeps the example short. In production, use the current UTC time. Also escape commas, semicolons and line breaks in summaries, since the format treats them as special.
How the data flows
Sharing rules
- Share a subscription link for
.icsfiles instead of emailing copies. Subscribed calendars refresh on their own, while emailed files go stale. - Export only what the audience needs. Executives may want launches only, so filter by status before you export.
- Keep one owner for the export job, and record where each copy lives.
Exercise
A teammate imports your .ics file each week and ends up with duplicate events. Name the likely cause and the fix.
Show answer
The export generates a new random UID on every run, so the calendar app sees each event as new. Build the UID from stable values, such as campaign, activity and start date, so the same activity always gets the same UID and the import updates the existing event.
Exercise
An activity runs from 2026-03-02 to 2026-03-04 inclusive. What DTSTART and DTEND values do you write for an all-day event?
Show answer
DTSTART;VALUE=DATE:20260302 and DTEND;VALUE=DATE:20260305. The all-day end date is exclusive, so you add one day to the last day of the activity.