From f6306c601515183a1f8238a8e4eb618da2ce4ebe Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 4 May 2018 19:20:23 +0200 Subject: [PATCH] Added Google Calendar plugin --- .../backend/http/static/css/widgets/music.css | 4 ++ platypush/plugins/google/calendar.py | 40 +++++++++++++++++++ platypush/plugins/google/credentials.py | 8 ++-- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 platypush/plugins/google/calendar.py diff --git a/platypush/backend/http/static/css/widgets/music.css b/platypush/backend/http/static/css/widgets/music.css index 3ed8d1e998..04f789a6c2 100644 --- a/platypush/backend/http/static/css/widgets/music.css +++ b/platypush/backend/http/static/css/widgets/music.css @@ -47,3 +47,7 @@ letter-spacing: 1px; } +.no-track-info { + font-size: 20px; +} + diff --git a/platypush/plugins/google/calendar.py b/platypush/plugins/google/calendar.py new file mode 100644 index 0000000000..fa38bae76c --- /dev/null +++ b/platypush/plugins/google/calendar.py @@ -0,0 +1,40 @@ +import base64 +import datetime +import httplib2 +import os + +from apiclient import discovery + +from platypush.message.response import Response +from platypush.plugins.google import GooglePlugin + + +class GoogleCalendarPlugin(GooglePlugin): + scopes = ['https://www.googleapis.com/auth/calendar.readonly'] + + def __init__(self, *args, **kwargs): + super().__init__(scopes=self.scopes, *args, **kwargs) + + + def get_upcoming_events(self, max_results=10): + now = datetime.datetime.utcnow().isoformat() + 'Z' + service = self._get_service() + result = service.events().list(calendarId='primary', timeMin=now, + maxResults=10, singleEvents=True, + orderBy='startTime').execute() + + events = result.get('items', []) + return Response(output=events) + + + def _get_service(self, scope=None): + if scope is None: + scope = self.scopes[0] + + credentials = self.credentials[scope] + http = credentials.authorize(httplib2.Http()) + return discovery.build('calendar', 'v3', http=http, cache_discovery=False) + + +# vim:sw=4:ts=4:et: + diff --git a/platypush/plugins/google/credentials.py b/platypush/plugins/google/credentials.py index 8086d1953b..1c1097c5ae 100644 --- a/platypush/plugins/google/credentials.py +++ b/platypush/plugins/google/credentials.py @@ -24,14 +24,14 @@ def get_credentials_filename(scope): def get_credentials(scope): credentials_file = get_credentials_filename(scope) if not os.path.exists(credentials_file): - raise RuntimeError('Credentials file {} not found. Generate it through:\n' + - '\tpython -m platypush.google.credentials "{}"' + + raise RuntimeError(('Credentials file {} not found. Generate it through:\n' + + '\tpython -m platypush.plugins.google.credentials "{}" ' + '\n' + '\t\t[--auth_host_name AUTH_HOST_NAME]\n' + '\t\t[--noauth_local_webserver]\n' + '\t\t[--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]\n' + - '\t\t[--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]\n'. - format(credentials_file, scope_name)) + '\t\t[--logging_level [DEBUG,INFO,WARNING,ERROR,CRITICAL]]\n'). + format(credentials_file, scope)) store = Storage(credentials_file) credentials = store.get()