From 2ab14d9cd30df7058b6f6863bbb47d00b3890f4c Mon Sep 17 00:00:00 2001 From: Diego Pereyra Date: Mon, 8 Aug 2022 21:59:27 -0300 Subject: [PATCH 1/5] Fix save token (using pickle) --- bumblebee_status/modules/contrib/gcalendar.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bumblebee_status/modules/contrib/gcalendar.py b/bumblebee_status/modules/contrib/gcalendar.py index e438bdd..c88cfad 100644 --- a/bumblebee_status/modules/contrib/gcalendar.py +++ b/bumblebee_status/modules/contrib/gcalendar.py @@ -29,6 +29,7 @@ import core.decorators import datetime import os.path +import pickle from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials @@ -60,7 +61,8 @@ class Module(core.module.Module): # created automatically when the authorization flow completes for the first # time. if os.path.exists(self.__token): - creds = Credentials.from_authorized_user_file(self.__token, SCOPES) + with open(self.__token, 'rb') as token: + creds = pickle.load(token) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -71,8 +73,8 @@ class Module(core.module.Module): ) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open(self.__token, "w") as token: - token.write(creds.to_json()) + with open(self.__token, 'wb') as token: + pickle.dump(creds, token) try: service = build("calendar", "v3", credentials=creds) From 124f13075d248a4c89a1bfce2df88dbab1e44e73 Mon Sep 17 00:00:00 2001 From: Diego Pereyra Date: Mon, 8 Aug 2022 21:59:39 -0300 Subject: [PATCH 2/5] Fix for multiple calendars --- bumblebee_status/modules/contrib/gcalendar.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/bumblebee_status/modules/contrib/gcalendar.py b/bumblebee_status/modules/contrib/gcalendar.py index c88cfad..769a24b 100644 --- a/bumblebee_status/modules/contrib/gcalendar.py +++ b/bumblebee_status/modules/contrib/gcalendar.py @@ -102,9 +102,6 @@ class Module(core.module.Module): ) events = events_result.get("items", []) - if not events: - return "No upcoming events found." - for event in events: start = dtparse( event["start"].get("dateTime", event["start"].get("date")) From 55f3085c903d7dbcce5ed45d7ca97e7dfa3cc96f Mon Sep 17 00:00:00 2001 From: Diego Pereyra Date: Mon, 8 Aug 2022 23:09:20 -0300 Subject: [PATCH 3/5] Added support for regolith fork of rofication (differs on the comm protocol: \n after command, receive values on csv) --- bumblebee_status/modules/contrib/rofication.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bumblebee_status/modules/contrib/rofication.py b/bumblebee_status/modules/contrib/rofication.py index 79e6afd..1fd5355 100644 --- a/bumblebee_status/modules/contrib/rofication.py +++ b/bumblebee_status/modules/contrib/rofication.py @@ -5,6 +5,10 @@ module will have normal highlighting if there are zero notifications, "warning" highlighting if there are nonzero notifications, "critical" highlighting if there are any critical notifications + + Parameters: + * rofication.regolith: Switch to regolith fork of rofication, see . + """ import core.module @@ -20,6 +24,7 @@ class Module(core.module.Module): super().__init__(config, theme, core.widget.Widget(self.full_text)) self.__critical = False self.__numnotifications = 0 + self.__regolith = self.parameter("regolith", False) def full_text(self, widgets): @@ -27,10 +32,16 @@ class Module(core.module.Module): client.connect("/tmp/rofi_notification_daemon") # below code will fetch two numbers in a list, e.g. ['22', '1'] # first is total number of notifications, second is number of critical notifications - client.sendall(bytes("num", "utf-8")) + if self.__regolith: + client.sendall(bytes("num\n", "utf-8")) + else: + client.sendall(bytes("num", "utf-8")) val = client.recv(512) val = val.decode("utf-8") - l = val.split('\n',2) + if self.__regolith: + l = val.split(',',2) + else: + l = val.split('\n',2) self.__numnotifications = int(l[0]) self.__critical = bool(int(l[1])) return self.__numnotifications From 80efa64614dc7b900639f4f6adec5cf4aac233ee Mon Sep 17 00:00:00 2001 From: Diego Pereyra Date: Wed, 10 Aug 2022 12:02:35 -0300 Subject: [PATCH 4/5] Support for locale on gcalendar --- bumblebee_status/modules/contrib/gcalendar.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bumblebee_status/modules/contrib/gcalendar.py b/bumblebee_status/modules/contrib/gcalendar.py index 769a24b..6d0f4ed 100644 --- a/bumblebee_status/modules/contrib/gcalendar.py +++ b/bumblebee_status/modules/contrib/gcalendar.py @@ -11,6 +11,7 @@ Parameters: * gcalendar.time_format: Format time output. Defaults to "%H:%M". * gcalendar.date_format: Format date output. Defaults to "%d.%m.%y". * gcalendar.credentials_path: Path to credentials.json. Defaults to "~/". + * gcalendar.locale: locale to use rather than the system default. Requires these pip packages: * google-api-python-client @@ -30,6 +31,7 @@ import core.decorators import datetime import os.path import pickle +import locale from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials @@ -50,6 +52,15 @@ class Module(core.module.Module): self.__credentials = os.path.join(self.__credentials_path, "credentials.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): SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"] From 2b3b9c0ca0405afb2346903e56b60bd32dd01cdd Mon Sep 17 00:00:00 2001 From: Diego Pereyra Date: Thu, 11 Aug 2022 12:26:04 -0300 Subject: [PATCH 5/5] Undo serialization using picke, added comment on minimum version for google-api-python-client --- bumblebee_status/modules/contrib/gcalendar.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bumblebee_status/modules/contrib/gcalendar.py b/bumblebee_status/modules/contrib/gcalendar.py index 6d0f4ed..efaabf7 100644 --- a/bumblebee_status/modules/contrib/gcalendar.py +++ b/bumblebee_status/modules/contrib/gcalendar.py @@ -14,7 +14,7 @@ Parameters: * gcalendar.locale: locale to use rather than the system default. Requires these pip packages: - * google-api-python-client + * google-api-python-client >= 1.8.0 * google-auth-httplib2 * google-auth-oauthlib """ @@ -30,7 +30,6 @@ import core.decorators import datetime import os.path -import pickle import locale from google.auth.transport.requests import Request @@ -72,8 +71,7 @@ class Module(core.module.Module): # created automatically when the authorization flow completes for the first # time. if os.path.exists(self.__token): - with open(self.__token, 'rb') as token: - creds = pickle.load(token) + creds = Credentials.from_authorized_user_file(self.__token, SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -84,8 +82,8 @@ class Module(core.module.Module): ) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open(self.__token, 'wb') as token: - pickle.dump(creds, token) + with open(self.__token, "w") as token: + token.write(creds.to_json()) try: service = build("calendar", "v3", credentials=creds)