feat: add support for 4PX tracking provider
Introduce support for the 4PX tracking provider by integrating the track4px library. Added the necessary dependencies and implemented the FourPX class to fetch and yield tracking status events, enhancing our logistics tracking capabilities.
This commit is contained in:
parent
fcfe4c4b83
commit
2664cabae0
2 changed files with 34 additions and 0 deletions
|
@ -22,6 +22,7 @@ dependencies = [
|
||||||
"fedextrack",
|
"fedextrack",
|
||||||
"dhltrack",
|
"dhltrack",
|
||||||
"dpdtrack",
|
"dpdtrack",
|
||||||
|
"track4px",
|
||||||
"sqlalchemy",
|
"sqlalchemy",
|
||||||
"alembic",
|
"alembic",
|
||||||
"python-dateutil",
|
"python-dateutil",
|
||||||
|
|
33
src/trackbert/providers/fourpx.py
Normal file
33
src/trackbert/providers/fourpx.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
from ..classes.provider import BaseProvider
|
||||||
|
from ..classes.database import Event
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from track4px.classes.api import Track4PX
|
||||||
|
|
||||||
|
|
||||||
|
class FourPX(BaseProvider):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_status(self, tracking_number, carrier):
|
||||||
|
api = Track4PX()
|
||||||
|
status = api.tracking(tracking_number, True)
|
||||||
|
|
||||||
|
for event in status.events:
|
||||||
|
event_time = event.datetime.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
yield Event(
|
||||||
|
shipment_id=0,
|
||||||
|
event_time=event_time,
|
||||||
|
event_description=f"{event.location + ' ' if event.location else ''}{event.description}",
|
||||||
|
raw_event=event.raw,
|
||||||
|
)
|
||||||
|
|
||||||
|
def supported_carriers(self):
|
||||||
|
return [
|
||||||
|
("4px", 100, "4PX"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
provider = FourPX
|
Loading…
Reference in a new issue