platypush/platypush/plugins/google/calendar.py

40 lines
1.1 KiB
Python
Raw Normal View History

2018-06-23 01:00:43 +02:00
"""
.. moduleauthor:: Fabio Manganiello <blacklight86@gmail.com>
"""
2018-05-04 19:20:23 +02:00
import datetime
from platypush.plugins import action
2018-05-04 19:20:23 +02:00
from platypush.plugins.google import GooglePlugin
from platypush.plugins.calendar import CalendarInterface
2018-05-04 19:20:23 +02:00
class GoogleCalendarPlugin(GooglePlugin, CalendarInterface):
2018-06-23 01:00:43 +02:00
"""
Google calendar plugin
"""
2018-05-04 19:20:23 +02:00
scopes = ['https://www.googleapis.com/auth/calendar.readonly']
def __init__(self, *args, **kwargs):
super().__init__(scopes=self.scopes, *args, **kwargs)
@action
2018-05-04 19:20:23 +02:00
def get_upcoming_events(self, max_results=10):
2018-06-23 01:00:43 +02:00
"""
Get the upcoming events. See
:func:`~platypush.plugins.calendar.CalendarPlugin.get_upcoming_events`.
"""
2018-05-04 19:20:23 +02:00
now = datetime.datetime.utcnow().isoformat() + 'Z'
service = self.get_service('calendar', 'v3')
2018-05-04 19:20:23 +02:00
result = service.events().list(calendarId='primary', timeMin=now,
maxResults=max_results, singleEvents=True,
2018-05-04 19:20:23 +02:00
orderBy='startTime').execute()
events = result.get('items', [])
return events
2018-05-04 19:20:23 +02:00
# vim:sw=4:ts=4:et: