Bump version to 0.2.4, add DPD tracker, and fix sorting of events.
This commit is contained in:
parent
ad44b1e1cc
commit
b12a7f71c5
3 changed files with 47 additions and 3 deletions
|
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "trackbert"
|
name = "trackbert"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
authors = [
|
authors = [
|
||||||
{ name="Kumi Mitterer", email="trackbert@kumi.email" },
|
{ name="Kumi Mitterer", email="trackbert@kumi.email" },
|
||||||
]
|
]
|
||||||
|
@ -23,6 +23,7 @@ dependencies = [
|
||||||
"glsapi",
|
"glsapi",
|
||||||
"fedextrack",
|
"fedextrack",
|
||||||
"dhltrack",
|
"dhltrack",
|
||||||
|
"dpdtrack",
|
||||||
"sqlalchemy",
|
"sqlalchemy",
|
||||||
"alembic",
|
"alembic",
|
||||||
"python-dateutil",
|
"python-dateutil",
|
||||||
|
|
|
@ -130,7 +130,7 @@ class Tracker:
|
||||||
logging.exception(f"Error querying API for {shipment.tracking_number}")
|
logging.exception(f"Error querying API for {shipment.tracking_number}")
|
||||||
return
|
return
|
||||||
|
|
||||||
events = sorted(events, key=lambda x: x.event_time, reverse=True)
|
events = sorted(events, key=lambda x: x.event_time)
|
||||||
|
|
||||||
if not events:
|
if not events:
|
||||||
logging.debug(f"No events found for {shipment.tracking_number}")
|
logging.debug(f"No events found for {shipment.tracking_number}")
|
||||||
|
@ -154,7 +154,7 @@ class Tracker:
|
||||||
):
|
):
|
||||||
event.shipment_id = shipment.id
|
event.shipment_id = shipment.id
|
||||||
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[-1])
|
||||||
|
|
||||||
def start_loop(self) -> Never:
|
def start_loop(self) -> Never:
|
||||||
logging.debug("Starting loop")
|
logging.debug("Starting loop")
|
||||||
|
|
43
src/trackbert/trackers/dpd.py
Normal file
43
src/trackbert/trackers/dpd.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
from .base import BaseTracker
|
||||||
|
from ..classes.database import Event
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from dpdtrack.classes.api import DPD as DPDAPI
|
||||||
|
|
||||||
|
|
||||||
|
class DPD(BaseTracker):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_status(self, tracking_number, carrier):
|
||||||
|
api = DPDAPI()
|
||||||
|
status = api.tracking(tracking_number)
|
||||||
|
|
||||||
|
events = status["data"][0]["lifecycle"]["entries"]
|
||||||
|
|
||||||
|
for event in events:
|
||||||
|
if "depotData" in event and event["depotData"] is not None:
|
||||||
|
event_location = f"[{', '.join(event['depotData'])}] "
|
||||||
|
else:
|
||||||
|
event_location = ""
|
||||||
|
|
||||||
|
event_timestamp = datetime.strptime(event["datetime"], "%Y%m%d%H%M%S")
|
||||||
|
event_time = event_timestamp.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
yield Event(
|
||||||
|
shipment_id=0,
|
||||||
|
event_time=event_time,
|
||||||
|
event_description=f"{event_location}{event['state']['text']}",
|
||||||
|
raw_event=json.dumps(event),
|
||||||
|
)
|
||||||
|
|
||||||
|
def supported_carriers(self):
|
||||||
|
return [
|
||||||
|
("dpd", 100, "DPD (Austria)"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
tracker = DPD
|
Loading…
Reference in a new issue