Added Google Calendar plugin
This commit is contained in:
parent
2f8c74c8e3
commit
f6306c6015
3 changed files with 48 additions and 4 deletions
|
@ -47,3 +47,7 @@
|
|||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.no-track-info {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
|
|
40
platypush/plugins/google/calendar.py
Normal file
40
platypush/plugins/google/calendar.py
Normal file
|
@ -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:
|
||||
|
|
@ -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 "{}" ' +
|
||||
'<path to client_secret.json>\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()
|
||||
|
|
Loading…
Reference in a new issue