:calendar: Bulk process events in a Google Calendar - clean out duplicate URLs and email addresses, move events from one month to the next
A command line tool to bulk process events in a Google Calendar:
See the built-in help:
python gcal_move_it.py
# clean:
- clean descriptions that have doubled-up URLs or email addresses
Usage: gcal_move_it.py clean <month 1..12> [options]
# move:
- Move non-recurring events from one month to the next month. (exception: a recurring event that was manually moved IS included)
- Only events that occurred before today are moved.
Usage: gcal_move_it.py move <source month 1..12> [options]
The options are:
[-b --blacklist - Specify a blacklist to exclude some events]
[-d --dryrun - Perform a dry run, without actually modifying the calendar]
[-h --help]
[-s --skipMovedRecurring] - Skip events that are recurring but were manually moved
[-t --targetdate - Specify an exact target date (instead of the default which is 'one month later')]
[-w --whitelist - Specify a whitelist to include only some events]
Examples:
gcal_move_it.py clean 1
gcal_move_it.py move 1
gcal_move_it.py move 1 -w urgent;important
gcal_move_it.py move 1 -b "cancelled;^done" -d -w urgent;important
gcal_move_it.py move 1 -w subject_1;subject_2 -t 2021-01-13
Try a dry run, that does not modify your calendar:
python gcal_move_it.py move 1 -d
Move events from March to the next month (April):
python gcal_move_it.py move 3
Clean events in February:
python gcal_move_it.py clean 2
Events are filtered, before deciding which events to process.
The following built-in rulies for filtering are always applied.
Events must be:
Exceptions:
Besides that, the optional black and white lists are applied, as specified via options on the command line.
A Google Calendar event can have a prefix added to its summary, to help filter via gcal-move-it.
Prefix | Description | Detail |
---|---|---|
[p] |
p inned to weekday |
If an event has the prefix [p] then it is considered as p inned to that day of the week. When the event is moved to the next month, the date will be adjusted to have the same day of the week. Note: the option -targetdate overrides this behavior. |
Together with the blacklist
or whitelist
options, you can use whatever custom prefixes or tags you like in your events. Below are some examples.
Prefix | Description | Detail |
---|---|---|
k |
OK meaning is ‘done’ |
The event is done, so it will NOT be moved to next month |
done |
Done | The event is done, so it will NOT be moved to next month |
n/a |
N ot A pplicable |
The event is no longer applicable, so it will NOT be moved to next month |
Get the credentials file
Use the Google Console to create a new project, and add the Google Calendar API to that project.
Option A
OAuth 2.0 Client IDs
Application Type
= Desktop app
Option B
To create the credentials file, add a service account. Download the key in JSON format (the UI can be tricky to use!).
See the Google documentation for more details.
Save the credentials file in this folder
So the file should be located at: ./credentials.json
pip install -r pip.config
gcal-move-it uses a few nice libraries:
Library | URL | Description |
---|---|---|
calendar | https://docs.python.org/3/library/calendar.html | For calendar operations like ‘get weekday for this date’ |
parameterized | https://pypi.org/project/parameterized/ | Easily parameterize your unit tests |
Tool | URL | Description |
---|---|---|
pip | https://pypi.org/project/pip/ | pip used with a config file, makes it easy to restore a Python project on another machine (even between Windows and Mac!) |
Google Calendar API - Concepts
Google Calendar API - Python client API
Python Babel library (used for dates)
License is MIT