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.repository',
'twilio',
'pytz',
'Adafruit_Python_DHT',
'RPi.GPIO',
'RPLCD',

View File

@ -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:

View File

@ -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'])

View File

@ -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