-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickstart.py
48 lines (39 loc) · 1.64 KB
/
quickstart.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from __future__ import print_function
import datetime
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import webreg_event
# If modifying these scopes, delete the file token.json.
# SCOPES = 'https://www.googleapis.com/auth/calendar.readonly'
SCOPES = 'https://www.googleapis.com/auth/calendar'
def main():
""" Log in user to the Google Calendar.
Creates calendar "Schedule 1".
Inserts recurrent events to the calendar.
"""
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('calendar', 'v3', http=creds.authorize(Http()))
# Create a new calendar for the convenience of testing
calendar = {
'summary': 'Schedule 1',
'timeZone': 'America/Los_Angeles'
}
created_calendar = service.calendars().insert(body=calendar).execute()
cal_id = created_calendar['id']
# Get events from pasteboard
events_to_add = webreg_event.generate_events_from_pasteboard()
for event in events_to_add:
# Add each event to the calendar just created
recurring_event = service.events().insert(calendarId=cal_id, body=event).execute()
event_id = recurring_event['id']
print("event summary: {} event id: {}".format(event["summary"], event_id))
if __name__ == '__main__':
main()