def sync_google_data_with_database(): """Shows basic usage of the Google Calendar API. Creates a Google Calendar API service object and outputs a list of the next 10 events on the user's calendar. """ credentials = get_credentials() http = credentials.authorize(httplib2.Http()) service = discovery.build('calendar', 'v3', http=http) now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time print('Getting the upcoming 10 events') eventsResult = service.events().list( calendarId='*****@*****.**', timeMin='2016-01-01T0:00:00+02:00', timeMax=now, singleEvents=True, orderBy='startTime').execute() events = eventsResult.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']) sync_database_with_retrieved_data(events) db_items = get_all_events() print('db_items size: ', len(db_items)) for item in db_items: print(item)
def sync_calendar_and_tasks_data(): events = get_all_events() reset_all_tasks_time_spent() for event in events: event_name = event[1] print(event_name) if event_name.startswith(EVENT_NAME_PREFIX) and event_name.endswith(EVENT_NAME_SUFFIX): try: id = int(event_name[3:-1]) print(id) if task_exists(id): print("Task exists") event_duration_seconds = event[3] - event[2] print(event_duration_seconds) increment_task_time_spent(id, event_duration_seconds) else: print("Task does not exist") except ValueError: print('not valid id')
def sync_calendar_and_tasks_data(): events = get_all_events() reset_all_tasks_time_spent() for event in events: event_name = event[1] print(event_name) if event_name.startswith(EVENT_NAME_PREFIX) and event_name.endswith( EVENT_NAME_SUFFIX): try: id = int(event_name[3:-1]) print(id) if task_exists(id): print("Task exists") event_duration_seconds = event[3] - event[2] print(event_duration_seconds) increment_task_time_spent(id, event_duration_seconds) else: print("Task does not exist") except ValueError: print('not valid id')