-
Notifications
You must be signed in to change notification settings - Fork 0
/
googlecalapi.py
26 lines (23 loc) · 969 Bytes
/
googlecalapi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def addtocalapi(birthdays):
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import datetime
# Setup the Calendar API
SCOPES = 'https://www.googleapis.com/auth/calendar'
store = file.Storage('credentials.json')
creds = None
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
CAL= build('calendar', 'v3', http=creds.authorize(Http()))
GMT_OFF='+05:30'
for k,v in birthdays.items():
day,month=v.split('/')
EVENT={
'summary':'It\'s %s\'s birthday today!'% k,
'start':{'dateTime':'2019-{}-{}T00:00:00{}'.format(month,day,GMT_OFF)},
'end':{'dateTime':'2019-{}-{}T14:00:00{}'.format(month,day,GMT_OFF)},
}
e=CAL.events().insert(calendarId='primary',body=EVENT).execute()
print(e['summary']+' added')