From 3e4b91cd6cffc1d5b5f271ade382d525de88a09e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 5 Jan 2022 18:04:32 +0100 Subject: [PATCH] Removed pytz dependency --- docs/source/conf.py | 1 - platypush/backend/github/__init__.py | 3 +-- platypush/plugins/calendar/ical/__init__.py | 22 ++++++++++++--------- setup.py | 2 -- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 74590b528..f551294e1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -276,7 +276,6 @@ autodoc_mock_imports = ['googlesamples.assistant.grpc.audio_helpers', 'gi', 'gi.repository', 'twilio', - 'pytz', 'Adafruit_Python_DHT', 'RPi.GPIO', 'RPLCD', diff --git a/platypush/backend/github/__init__.py b/platypush/backend/github/__init__.py index f4a2e8fe0..ad49b73d4 100644 --- a/platypush/backend/github/__init__.py +++ b/platypush/backend/github/__init__.py @@ -4,7 +4,6 @@ import threading from typing import Optional, List -import pytz import requests from sqlalchemy import create_engine, Column, String, DateTime from sqlalchemy.ext.declarative import declarative_base @@ -129,7 +128,7 @@ class GithubBackend(Backend): def _get_last_event_time(self, uri: str): with self.db_lock: record = self._get_or_create_resource(uri=uri, session=Session()) - return record.last_updated_at.replace(tzinfo=pytz.UTC) if record.last_updated_at else None + return record.last_updated_at.replace(tzinfo=datetime.timezone.utc) if record.last_updated_at else None def _update_last_event_time(self, uri: str, last_updated_at: datetime.datetime): with self.db_lock: diff --git a/platypush/plugins/calendar/ical/__init__.py b/platypush/plugins/calendar/ical/__init__.py index fdebdf705..c8e8c7cda 100644 --- a/platypush/plugins/calendar/ical/__init__.py +++ b/platypush/plugins/calendar/ical/__init__.py @@ -3,9 +3,8 @@ """ import datetime -import dateutil.parser import requests -from typing import Union, Optional +from typing import Optional from platypush.plugins import Plugin, action from platypush.plugins.calendar import CalendarInterface @@ -30,16 +29,22 @@ class CalendarIcalPlugin(Plugin, CalendarInterface): self.url = url @staticmethod - def _convert_timestamp(event, attribute: str) -> datetime.datetime: - import pytz + def _convert_timestamp(event, attribute: str) -> Optional[str]: t = event.get(attribute) if not t: return + if type(t.dt) == datetime.date: + return ( + datetime.datetime( + t.dt.year, t.dt.month, t.dt.day, tzinfo=datetime.timezone.utc + ).isoformat() + ) + return ( - dateutil.parser.isoparse(t.dt.isoformat()) - .replace(tzinfo=pytz.timezone('UTC')) - ).isoformat() + datetime.datetime.utcfromtimestamp(t.dt.timestamp()) + .replace(tzinfo=datetime.timezone.utc).isoformat() + ) @classmethod def _translate_event(cls, event): @@ -77,7 +82,6 @@ class CalendarIcalPlugin(Plugin, CalendarInterface): :func:`~platypush.plugins.calendar.CalendarPlugin.get_upcoming_events`. """ - import pytz from icalendar import Calendar events = [] @@ -95,7 +99,7 @@ class CalendarIcalPlugin(Plugin, CalendarInterface): if ( event['status'] != 'cancelled' and event['end'].get('dateTime') - and event['end']['dateTime'] >= datetime.datetime.now(pytz.timezone('UTC')).isoformat() + and event['end']['dateTime'] >= datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat() and ( (only_participating and event.get('responseStatus') in [None, 'accepted', 'tentative']) diff --git a/setup.py b/setup.py index f0f317158..fbfc2c9a3 100755 --- a/setup.py +++ b/setup.py @@ -230,8 +230,6 @@ setup( 'dbus': ['dbus-python'], # Support for Twilio integration 'twilio': ['twilio'], - # Support for Github integration - 'github': ['pytz'], # Support for DHT11/DHT22/AM2302 temperature/humidity sensors 'dht': ['Adafruit_Python_DHT @ git+https://github.com/adafruit/Adafruit_Python_DHT'], # Support for LCD display integration