Removed pytz dependency

This commit is contained in:
Fabio Manganiello 2022-01-05 18:04:32 +01:00
parent e242dc53bf
commit 3e4b91cd6c
Signed by: blacklight
GPG key ID: D90FBA7F76362774
4 changed files with 14 additions and 14 deletions

View file

@ -276,7 +276,6 @@ autodoc_mock_imports = ['googlesamples.assistant.grpc.audio_helpers',
'gi', 'gi',
'gi.repository', 'gi.repository',
'twilio', 'twilio',
'pytz',
'Adafruit_Python_DHT', 'Adafruit_Python_DHT',
'RPi.GPIO', 'RPi.GPIO',
'RPLCD', 'RPLCD',

View file

@ -4,7 +4,6 @@ import threading
from typing import Optional, List from typing import Optional, List
import pytz
import requests import requests
from sqlalchemy import create_engine, Column, String, DateTime from sqlalchemy import create_engine, Column, String, DateTime
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
@ -129,7 +128,7 @@ class GithubBackend(Backend):
def _get_last_event_time(self, uri: str): def _get_last_event_time(self, uri: str):
with self.db_lock: with self.db_lock:
record = self._get_or_create_resource(uri=uri, session=Session()) 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): def _update_last_event_time(self, uri: str, last_updated_at: datetime.datetime):
with self.db_lock: with self.db_lock:

View file

@ -3,9 +3,8 @@
""" """
import datetime import datetime
import dateutil.parser
import requests import requests
from typing import Union, Optional from typing import Optional
from platypush.plugins import Plugin, action from platypush.plugins import Plugin, action
from platypush.plugins.calendar import CalendarInterface from platypush.plugins.calendar import CalendarInterface
@ -30,16 +29,22 @@ class CalendarIcalPlugin(Plugin, CalendarInterface):
self.url = url self.url = url
@staticmethod @staticmethod
def _convert_timestamp(event, attribute: str) -> datetime.datetime: def _convert_timestamp(event, attribute: str) -> Optional[str]:
import pytz
t = event.get(attribute) t = event.get(attribute)
if not t: if not t:
return 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 ( return (
dateutil.parser.isoparse(t.dt.isoformat()) datetime.datetime.utcfromtimestamp(t.dt.timestamp())
.replace(tzinfo=pytz.timezone('UTC')) .replace(tzinfo=datetime.timezone.utc).isoformat()
).isoformat() )
@classmethod @classmethod
def _translate_event(cls, event): def _translate_event(cls, event):
@ -77,7 +82,6 @@ class CalendarIcalPlugin(Plugin, CalendarInterface):
:func:`~platypush.plugins.calendar.CalendarPlugin.get_upcoming_events`. :func:`~platypush.plugins.calendar.CalendarPlugin.get_upcoming_events`.
""" """
import pytz
from icalendar import Calendar from icalendar import Calendar
events = [] events = []
@ -95,7 +99,7 @@ class CalendarIcalPlugin(Plugin, CalendarInterface):
if ( if (
event['status'] != 'cancelled' event['status'] != 'cancelled'
and event['end'].get('dateTime') 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 ( and (
(only_participating (only_participating
and event.get('responseStatus') in [None, 'accepted', 'tentative']) and event.get('responseStatus') in [None, 'accepted', 'tentative'])

View file

@ -230,8 +230,6 @@ setup(
'dbus': ['dbus-python'], 'dbus': ['dbus-python'],
# Support for Twilio integration # Support for Twilio integration
'twilio': ['twilio'], 'twilio': ['twilio'],
# Support for Github integration
'github': ['pytz'],
# Support for DHT11/DHT22/AM2302 temperature/humidity sensors # Support for DHT11/DHT22/AM2302 temperature/humidity sensors
'dht': ['Adafruit_Python_DHT @ git+https://github.com/adafruit/Adafruit_Python_DHT'], 'dht': ['Adafruit_Python_DHT @ git+https://github.com/adafruit/Adafruit_Python_DHT'],
# Support for LCD display integration # Support for LCD display integration