chore: Run black on code

This commit is contained in:
Kumi 2023-08-24 17:43:23 +02:00
parent 9374b1284e
commit 1d90de9205
Signed by: kumi
GPG key ID: ECBCC9082395383F
4 changed files with 29 additions and 20 deletions

View file

@ -90,7 +90,7 @@ class Tracker:
except FileNotFoundError: except FileNotFoundError:
logging.warning("notify-send not found, not sending notification") logging.warning("notify-send not found, not sending notification")
def notify_event(self, shipment, event, critical = False) -> None: def notify_event(self, shipment, event, critical=False) -> None:
logging.info( logging.info(
f"New event for {shipment.tracking_number}: {event.event_description} - {event.event_time}" f"New event for {shipment.tracking_number}: {event.event_description} - {event.event_time}"
) )
@ -141,7 +141,6 @@ class Tracker:
self.db.write_event(event) self.db.write_event(event)
self.notify_event(shipment, event, event == events[0]) self.notify_event(shipment, event, event == events[0])
def start_loop(self) -> Never: def start_loop(self) -> Never:
logging.debug("Starting loop") logging.debug("Starting loop")
@ -159,7 +158,10 @@ class Tracker:
while True: while True:
tasks = [] tasks = []
for shipment in self.db.get_shipments(): for shipment in self.db.get_shipments():
task = asyncio.wait_for(asyncio.to_thread(self.process_shipment, shipment), timeout=self.loop_timeout) task = asyncio.wait_for(
asyncio.to_thread(self.process_shipment, shipment),
timeout=self.loop_timeout,
)
tasks.append(task) tasks.append(task)
try: try:

View file

@ -15,19 +15,23 @@ class KeyDelivery(BaseTracker):
all_events = self.api.realtime(carrier, tracking_number) all_events = self.api.realtime(carrier, tracking_number)
try: try:
logging.debug(f"Got events for {tracking_number}: {len(all_events['data']['items'])}") logging.debug(
f"Got events for {tracking_number}: {len(all_events['data']['items'])}"
)
except KeyError: except KeyError:
print(f"Error getting events for {tracking_number}: {all_events}") print(f"Error getting events for {tracking_number}: {all_events}")
return return
events = sorted(all_events["data"]["items"], key=lambda x: x["time"], reverse=True) events = sorted(
all_events["data"]["items"], key=lambda x: x["time"], reverse=True
)
for event in events: for event in events:
yield Event( yield Event(
shipment_id = 0, shipment_id=0,
event_time = event["time"], event_time=event["time"],
event_description = event["context"], event_description=event["context"],
raw_event = json.dumps(event) raw_event=json.dumps(event),
) )
@staticmethod @staticmethod
@ -36,4 +40,5 @@ class KeyDelivery(BaseTracker):
("*", 1), ("*", 1),
] ]
tracker = KeyDelivery tracker = KeyDelivery

View file

@ -6,6 +6,7 @@ import json
from dateutil.parser import parse from dateutil.parser import parse
from postat.classes.api import PostAPI from postat.classes.api import PostAPI
class PostAT(BaseTracker): class PostAT(BaseTracker):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
pass pass
@ -21,10 +22,10 @@ class PostAT(BaseTracker):
py_timestamp = parse(timestamp) py_timestamp = parse(timestamp)
event_time = py_timestamp.strftime("%Y-%m-%d %H:%M:%S") event_time = py_timestamp.strftime("%Y-%m-%d %H:%M:%S")
yield Event( yield Event(
shipment_id = 0, shipment_id=0,
event_time = event_time, event_time=event_time,
event_description = event["text"], event_description=event["text"],
raw_event = json.dumps(event) raw_event=json.dumps(event),
) )
@staticmethod @staticmethod
@ -33,4 +34,5 @@ class PostAT(BaseTracker):
("austrian_post", 100), ("austrian_post", 100),
] ]
tracker = PostAT tracker = PostAT