Getting started
Installation
To install gcsa
run the following command:
pip install gcsa
from sources:
git clone git@github.com:kuzmoyev/google-calendar-simple-api.git
cd google-calendar-simple-api
python setup.py install
Credentials
Now you need to get your API credentials:
Note
You will need to enable the “Google Calendar API” for your project.
Create a OAuth client ID credential and download the
credentials.json
(client_secret_*.json
) filePut downloaded
credentials.json
(client_secret_*.json
) file into~/.credentials/
directory
See more options in Authentication.
Note
You can put
credentials.json
(client_secret_*.json
) file anywhere you want and specify the path to it in your code afterwords. But remember not to share it (e.g. add it to.gitignore
) as it is your private credentials.Note
On the first run, your application will prompt you to the default browser to get permissions from you to use your calendar. This will createtoken.pickle
file in the same folder (unless specified otherwise) as yourcredentials.json
(client_secret_*.json
). So don’t forget to also add it to.gitignore
if it is in a GIT repository.If you don’t want to save it in.pickle
file, you can usesave_token=False
when initializing theGoogleCalendar
.
Quick example
The following code will create a recurrent event in your calendar starting on January 1 and repeating everyday at 9:00am except weekends and two holidays (April 19, April 22).
Then it will list all events for one year starting today.
For date
/datetime
objects you can use Pythons datetime module or as in the
example beautiful_date library (because it’s beautiful… just like you).
from gcsa.event import Event
from gcsa.google_calendar import GoogleCalendar
from gcsa.recurrence import Recurrence, DAILY, SU, SA
from beautiful_date import Jan, Apr
calendar = GoogleCalendar('your_email@gmail.com')
event = Event(
'Breakfast',
start=(1 / Jan / 2019)[9:00],
recurrence=[
Recurrence.rule(freq=DAILY),
Recurrence.exclude_rule(by_week_day=[SU, SA]),
Recurrence.exclude_times([
(19 / Apr / 2019)[9:00],
(22 / Apr / 2019)[9:00]
])
],
minutes_before_email_reminder=50
)
calendar.add_event(event)
for event in calendar:
print(event)