Verified Commit 3e4b91cd authored by Fabio Manganiello's avatar Fabio Manganiello
Browse files

Removed pytz dependency

parent e242dc53
Pipeline #134 passed with stages
in 6 minutes and 2 seconds
......@@ -276,7 +276,6 @@ autodoc_mock_imports = ['googlesamples.assistant.grpc.audio_helpers',
'gi',
'gi.repository',
'twilio',
'pytz',
'Adafruit_Python_DHT',
'RPi.GPIO',
'RPLCD',
......
......@@ -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:
......
......@@ -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'])
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment