Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
chatBot/quickstart.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38 lines (33 sloc)
1.39 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import datetime | |
from googleapiclient.discovery import build | |
from httplib2 import Http | |
from oauth2client import file, client, tools | |
from changes2 import maxResults | |
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly' | |
maxResults = maxResults | |
def main(): | |
"""Shows basic usage of the Google Calendar API. | |
Prints the start and name of the next 10 events on the user's calendar. | |
""" | |
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())) | |
# Call the Calendar API | |
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time | |
print('Getting the upcoming',maxResults,'events') | |
events_result = service.events().list(calendarId='primary', timeMin=now, | |
maxResults=maxResults, singleEvents=True, | |
orderBy='startTime').execute() | |
events = events_result.get('items', []) | |
if not events: | |
print('No upcoming events found.') | |
for event in events: | |
start = event['start'].get('dateTime', event['start'].get('date')) | |
print(start, event['summary']) | |
print(type(start)) | |
if __name__ == '__main__': | |
main() |