Sub topic 11
Exporting and sharing the calendar
This chapter assumes you have a flat calendar table with one row per activity, as built in the earlier chapters. It also assumes you can read short Python scripts. By the end you will be able to export that table to CSV and iCalendar, choose a sharing method for each audience, and avoid the failures that make shared copies drift out of date.
Why export at all
Your calendar tool is the source of truth, but not everyone works in it. Finance wants a spreadsheet. Sales wants launch dates in their own calendar app. An agency wants a weekly snapshot. A dashboard tool wants a table to join against results.
Exporting is how the calendar reaches these people without giving each of them edit access. The aim is to keep one editable master and make every other copy either read-only or regenerated from the master.
Choosing a sharing method
Different consumers need different mechanisms. The table lists the common ones.
| Method | Best for | Stays current? | Main risk |
|---|---|---|---|
| CSV export | Spreadsheets, BI tools, audits | No, it is a snapshot | Stale copies circulate by email |
| iCalendar (.ics) file import | One-off hand-off to a person or agency | No, it is a snapshot | Re-importing creates duplicates |
| iCalendar subscription feed | Stakeholders who live in a calendar app | Yes, with a delay | Refresh lag and accidental public links |
| Read-only shared view | Executives and cross-team partners | Yes | View permissions are wider than intended |
| API or automation | Dashboards, chat alerts, other systems | Yes | Needs an owner to maintain the integration |
Choose by asking two questions. Does the reader need live data, or is a snapshot enough? Does the reader need to act on the data, or only to see it? Snapshots are acceptable for audits and agency hand-offs. People who plan around dates need a live view or a subscription.
Exporting to CSV
CSV is the simplest format. It is plain text, one row per line, and every spreadsheet and data tool can read it. The calendar data model from earlier chapters already maps onto it directly:
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-10A few conventions prevent most CSV problems:
- Write dates as ISO 8601 (
2026-03-02). Regional formats such as03/02/2026are read differently in different countries. - Use UTF-8 encoding. Campaign names often contain accents, symbols and emoji.
- Keep one header row with stable column names. Downstream formulas and dashboards break when someone renames
ownertoOwner (DRI). - Quote any field that contains a comma or line break. Most export tools do this for you, but hand-built exports often do not.
- Put a generated-at timestamp in the file name, for example
calendar-2026-02-26.csv, so readers can tell how old a snapshot is.
Also decide which columns to export. The master may hold budgets, agency rates or embargoed announcement dates. A CSV sent to a wider audience should include only the fields that audience needs.
Exporting to iCalendar
iCalendar (the .ics format) is the standard that Google Calendar, Outlook and Apple Calendar all understand. An export turns each calendar row into an event. Here is the smallest useful file, with one all-day event:
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:VCALENDARThe fields that matter most:
UIDidentifies the event. A calendar app uses it to decide whether an incoming event is new or an update to one it already has.DTSTAMPrecords when the event data was generated.DTSTART;VALUE=DATEmarks an all-day event. Most campaign activities are all-day, which also avoids time zone problems.DTENDfor an all-day event is exclusive, so it is the day after the last day. A one-day event on 2 March ends on 3 March. Writing the same date for start and end makes some apps drop the event or show it with zero length.SUMMARYis the title people see in their calendar.
The specification also requires CRLF (\r\n) line endings. Text longer than 75 bytes must be folded onto continuation lines that begin with a space. In SUMMARY and DESCRIPTION, commas, semicolons, backslashes and line breaks must be escaped.
Generating the file from your table
Writing .ics by hand does not scale. This script converts the CSV into a calendar file and handles the escaping, folding, line endings and the exclusive end date.
import csv
import io
import re
from datetime import date, datetime, timedelta, timezone
CSV_TEXT = """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-10
"""
def escape(text: str) -> str:
return (
text.replace("\\", "\\\\")
.replace(";", "\\;")
.replace(",", "\\,")
.replace("\n", "\\n")
)
def slug(text: str) -> str:
return re.sub(r"[^a-z0-9]+", "-", text.lower()).strip("-")
def fold(line: str) -> str:
"""Fold a content line so no physical line exceeds 75 bytes."""
parts, current = [], ""
for ch in line:
if len((current + ch).encode("utf-8")) > 75:
parts.append(current)
current = " " + ch
else:
current += ch
parts.append(current)
return "\r\n".join(parts)
def build_event(row: dict, stamp: str) -> list[str]:
start = date.fromisoformat(row["start_date"])
end = date.fromisoformat(row["end_date"]) + timedelta(days=1) # exclusive
uid = f"{slug(row['campaign'])}-{slug(row['activity'])}@example.com"
description = (
f"Owner: {row['owner']}. Status: {row['status']}. "
f"Channel: {row['channel']}."
)
return [
"BEGIN:VEVENT",
f"UID:{uid}",
f"DTSTAMP:{stamp}",
f"DTSTART;VALUE=DATE:{start:%Y%m%d}",
f"DTEND;VALUE=DATE:{end:%Y%m%d}",
f"SUMMARY:{escape(row['campaign'] + ': ' + row['activity'])}",
f"DESCRIPTION:{escape(description)}",
"END:VEVENT",
]
def build_calendar(rows) -> str:
stamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
lines = [
"BEGIN:VCALENDAR",
"VERSION:2.0",
"PRODID:-//Example Marketing//Campaign Calendar//EN",
]
for row in rows:
lines.extend(build_event(row, stamp))
lines.append("END:VCALENDAR")
return "\r\n".join(fold(line) for line in lines) + "\r\n"
rows = list(csv.DictReader(io.StringIO(CSV_TEXT)))
with open("campaign-calendar.ics", "w", encoding="utf-8", newline="") as f:
f.write(build_calendar(rows))
print(f"Wrote {len(rows)} events")Open the file in a calendar app to check it. The "Social teaser" event should span 27 February to 1 March inclusive. If it ends a day early, the exclusive end date was not applied.
Note newline="" when opening the file. Without it, Python on Windows converts \r\n to \r\r\n and some importers reject the result.
Keeping UIDs stable
The UID is the most common source of problems. A calendar app treats two events with the same UID as the same event, so the second import updates the first. Two events with different UIDs are both kept.
If your script generates a new random UID on every run, each import adds a full duplicate set. If the UID is built from a name that people edit, renaming an activity makes the old event linger beside the new one.
The best fix is a permanent ID column in the master table, set when a row is created and never edited. The script above derives the UID from the campaign and activity names, which works for a demonstration but breaks on renames. When you change an event that people have already imported, also raise its SEQUENCE number so apps know it is a newer version.
Snapshots versus subscriptions
A file import is a snapshot. The recipient's calendar copies the events, and later changes in the master never reach it. This is fine for an agency kickoff. It is a poor choice for a stakeholder who will plan around the dates for six months.
A subscription feed works differently. You publish the .ics file at a URL, regenerate it whenever the master changes, and recipients subscribe to the URL. Their calendar app polls it and applies updates, using the UID to match events. Because the feed is a full replacement each time, a deleted row disappears from subscribers' calendars on the next refresh. That is usually what you want.
Many tools offer a built-in feed or a "publish to calendar" option. Prefer that to a home-made feed when it exists, because someone else maintains it.
Controlling what you share
Anything in a shared file or feed is outside your permission system. Before you publish, decide three things:
- Who can see it. A feed URL is often the only protection, so anyone holding the link can read it. Treat the URL as a secret and avoid pasting it into public channels.
- Which rows are included. Statuses such as
draftmay hold unapproved ideas. A feed for partners might include only items pastin_review. - Which fields are included. Budgets, internal commentary and unannounced product names do not belong in an event description.
A good pattern is one filtered feed per audience. Examples are an "all approved launches" feed for sales and a "paid media only" feed for the agency. Building these is a filter step in front of the same script.
Common failure modes
- Duplicate events after re-import. Cause: UIDs changed between exports. Fix: use a permanent ID.
- Events shifted by a day. Cause: the all-day end date was not made exclusive, or timed events had no time zone. Fix: add one day to the end date, or use UTC or a
TZIDfor timed events. - Garbled names. Cause: a CSV saved in a legacy encoding. Fix: export UTF-8.
- A spreadsheet that rewrites dates. Cause: opening the CSV in an app that guesses types. Fix: import the file with the date columns declared as text or ISO dates.
- Stale snapshots in circulation. Cause: files attached to emails. Fix: put the date in the file name and link to the live view instead of attaching files.
- A broken feed that nobody notices. Cause: the regeneration job fails quietly. Fix: assign an owner and add a check that the feed's newest
DTSTAMPis recent.
The last point connects to governance. An export is only as reliable as the person who owns it, so give each shared output a named owner, as you do for each calendar entry.
Exercise
A teammate exports a three-day activity running 10 to 12 March 2026 as an all-day event. They write DTSTART;VALUE=DATE:20260310 and DTEND;VALUE=DATE:20260312. What shows up in the recipient's calendar, and what should the DTEND be?
Show answer
The event shows only on 10 and 11 March, because an all-day DTEND is exclusive. It should be DTEND;VALUE=DATE:20260313, which is the day after the last day of the activity.
Exercise
Your export script generates a random UID for every event on each run. The sales team imports the file weekly. What goes wrong, and how do you fix it?
Show answer
Each import adds a new copy of every event, because the calendar app sees different UIDs and treats them as new events. Fix it by giving each calendar row a permanent ID, building the UID from that ID, and publishing a subscription feed so updates replace the old events instead of adding to them.
Exercise
An agency needs the paid-media schedule but must not see unreleased product names in draft rows. Which sharing method and filters would you choose?
Show answer
Use a filtered iCalendar feed or CSV limited to rows with channel "paid" and a status past draft, with only the fields the agency needs. Exclude descriptions or comments that contain internal notes. Keep the feed URL private and name an owner for the regeneration job.