Skip to content

Instantly share code, notes, and snippets.

@sdolenc
Last active June 23, 2023 14:25
Show Gist options
  • Save sdolenc/4a3dc2a8ef79cee1acdab625eb808c85 to your computer and use it in GitHub Desktop.
Save sdolenc/4a3dc2a8ef79cee1acdab625eb808c85 to your computer and use it in GitHub Desktop.
Import Recurring Events to Google Calendar

One method of quickly creating a lot of events in google calendar is to import a CSV file. However, there is no support for directly adding "recurring" events (birthdays, anniversaries, etc). Here's the workarond.

Summarized steps

  1. create csv file with events (no recurring)
  2. import csv into a new, temporary google calendar
  3. export temporary google calendar to an ics file
  4. edit ics file to change events into recurring
  5. import ics file into a new, permanent google calendar.
  6. delete temporary google calendar

Detailed steps

1. create csv file with events (no recurring)

The CSV format can be found at https://support.google.com/calendar/answer/37118?hl=en

example csv

2. import csv into a new, temporary google calendar

3. export temporary google calendar to an ics file

4. edit ics file to change events into recurring

4a. manually by adding RRULE:FREQ=YEARLY between each set of VEVENT begin/close statements. For example:

BEGIN:VEVENT
DTSTART;VALUE=DATE:20180520
DTEND;VALUE=DATE:20180521
RRULE:FREQ=YEARLY
...
END:VEVENT

or

4b. automatically by running this python

import icalendar
import os

def make_recurring():
    directory = os.path.dirname(__file__)
    with open(os.path.join(directory, 'noRecur.ics'), 'r') as fr:
        data = fr.read()

    cal = icalendar.Calendar.from_ical(data)
    for event in cal.subcomponents:
        if 'RRULE' not in event.keys():
            event.add('rrule', {'freq': ['YEARLY']})

    with open(os.path.join(directory, 'withRecur.ics'), 'wb') as fw:
        fw.write(cal.to_ical())

5. import ics file into a new, permanent google calendar.

6. delete temporary google calendar

@okimselim
Copy link

Why waste time with python? Just open the .ics in a text editor and find/replace all

END:VEVENT

with

RRULE:FREQ=YEARLY
END:VEVENT

Done in 2 seconds.

@Hsad1644
Copy link

Hsad1644 commented Feb 13, 2023

Yeah I lost that script to my cache memory xP (so thanks for your comment since you led me back to it). This is what i do now. alt + D on vscode helps a bunch because I use this for making my semester's weekly schedule.

The script was more like a solution to add to an app that I have planned to make for our uni.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment