restructures programm into multiple functions
This commit is contained in:
parent
571c5a9e0e
commit
7fd7b69f65
@ -0,0 +1,5 @@
|
||||
### Requirements
|
||||
from [this google tutorial](https://developers.google.com/calendar/quickstart/python)
|
||||
|
||||
to run the scripts in this repository, please install
|
||||
pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
|
@ -10,10 +10,7 @@ from google.auth.transport.requests import Request
|
||||
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
|
||||
|
||||
|
||||
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.
|
||||
"""
|
||||
def calendarCredentials():
|
||||
creds = None
|
||||
# The file token.pickle stores the user's access and refresh tokens, and is
|
||||
# created automatically when the authorization flow completes for the first
|
||||
@ -35,12 +32,9 @@ def main():
|
||||
|
||||
service = build('calendar', 'v3', credentials=creds)
|
||||
|
||||
# Call the Calendar API
|
||||
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
|
||||
one_day = datetime.timedelta(days=1)
|
||||
tom = (datetime.datetime.utcnow() + one_day).isoformat() + 'Z'
|
||||
print('Getting todays calendar events')
|
||||
return service
|
||||
|
||||
def getCalendarEvents(service, startDate, endDate):
|
||||
page_token = None
|
||||
calendar_ids = []
|
||||
while True:
|
||||
@ -51,18 +45,33 @@ def main():
|
||||
if not page_token:
|
||||
break
|
||||
|
||||
all_events = []
|
||||
|
||||
for calendar in calendar_ids:
|
||||
print(calendar)
|
||||
events_result = service.events().list(calendarId=calendar, timeMin=now,
|
||||
timeMax=tom,
|
||||
events_result = service.events().list(calendarId=calendar, timeMin=startDate,
|
||||
timeMax=endDate,
|
||||
maxResults=10, singleEvents=True,
|
||||
orderBy='startTime').execute()
|
||||
events = events_result.get('items', [])
|
||||
all_events.append(events_result.get('items', []))
|
||||
|
||||
if not events:
|
||||
print('No upcoming events found.')
|
||||
for event in events:
|
||||
return all_events
|
||||
|
||||
def main():
|
||||
|
||||
service = calendarCredentials()
|
||||
# Call the Calendar API
|
||||
now = datetime.datetime.now()
|
||||
now = now.replace(hour=00, minute=00)
|
||||
today = now.isoformat() + 'Z' # 'Z' indicates UTC time
|
||||
one_day = datetime.timedelta(days=1)
|
||||
tomorrow = (now + one_day).isoformat() + 'Z'
|
||||
|
||||
all_events = getCalendarEvents(service, today, tomorrow)
|
||||
|
||||
# if not events:
|
||||
# print('No upcoming events found.')
|
||||
for event_list in all_events:
|
||||
for event in event_list:
|
||||
start = event['start'].get('dateTime', event['start'].get('date'))
|
||||
print(start, event['summary'])
|
||||
|
||||
|
BIN
token.pickle
BIN
token.pickle
Binary file not shown.
Loading…
Reference in New Issue
Block a user