commit
fed7a067ba
1 changed files with 12 additions and 4 deletions
|
@ -11,9 +11,10 @@ Parameters:
|
||||||
* gcalendar.time_format: Format time output. Defaults to "%H:%M".
|
* gcalendar.time_format: Format time output. Defaults to "%H:%M".
|
||||||
* gcalendar.date_format: Format date output. Defaults to "%d.%m.%y".
|
* gcalendar.date_format: Format date output. Defaults to "%d.%m.%y".
|
||||||
* gcalendar.credentials_path: Path to credentials.json. Defaults to "~/".
|
* gcalendar.credentials_path: Path to credentials.json. Defaults to "~/".
|
||||||
|
* gcalendar.locale: locale to use rather than the system default.
|
||||||
|
|
||||||
Requires these pip packages:
|
Requires these pip packages:
|
||||||
* google-api-python-client
|
* google-api-python-client >= 1.8.0
|
||||||
* google-auth-httplib2
|
* google-auth-httplib2
|
||||||
* google-auth-oauthlib
|
* google-auth-oauthlib
|
||||||
"""
|
"""
|
||||||
|
@ -29,6 +30,7 @@ import core.decorators
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import os.path
|
import os.path
|
||||||
|
import locale
|
||||||
|
|
||||||
from google.auth.transport.requests import Request
|
from google.auth.transport.requests import Request
|
||||||
from google.oauth2.credentials import Credentials
|
from google.oauth2.credentials import Credentials
|
||||||
|
@ -49,6 +51,15 @@ class Module(core.module.Module):
|
||||||
self.__credentials = os.path.join(self.__credentials_path, "credentials.json")
|
self.__credentials = os.path.join(self.__credentials_path, "credentials.json")
|
||||||
self.__token = os.path.join(self.__credentials_path, ".gcalendar_token.json")
|
self.__token = os.path.join(self.__credentials_path, ".gcalendar_token.json")
|
||||||
|
|
||||||
|
l = locale.getdefaultlocale()
|
||||||
|
if not l or l == (None, None):
|
||||||
|
l = ("en_US", "UTF-8")
|
||||||
|
lcl = self.parameter("locale", ".".join(l))
|
||||||
|
try:
|
||||||
|
locale.setlocale(locale.LC_TIME, lcl.split("."))
|
||||||
|
except Exception:
|
||||||
|
locale.setlocale(locale.LC_TIME, ("en_US", "UTF-8"))
|
||||||
|
|
||||||
def first_event(self, widget):
|
def first_event(self, widget):
|
||||||
SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"]
|
SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"]
|
||||||
|
|
||||||
|
@ -100,9 +111,6 @@ class Module(core.module.Module):
|
||||||
)
|
)
|
||||||
events = events_result.get("items", [])
|
events = events_result.get("items", [])
|
||||||
|
|
||||||
if not events:
|
|
||||||
return "No upcoming events found."
|
|
||||||
|
|
||||||
for event in events:
|
for event in events:
|
||||||
start = dtparse(
|
start = dtparse(
|
||||||
event["start"].get("dateTime", event["start"].get("date"))
|
event["start"].get("dateTime", event["start"].get("date"))
|
||||||
|
|
Loading…
Reference in a new issue