コード例 #1
0
def _extract_tracking(tracking_node: Element, settings) -> TrackingDetails:
    tracking: TrackInfoType = TrackInfoType()
    tracking.build(tracking_node)
    track_detail_nodes = tracking_node.xpath(".//*[local-name() = $name]",
                                             name="TrackDetail")
    details: List[TrackDetailType] = [
        (lambda t: (t, t.build(detail)))(TrackDetailType())[0]
        for detail in track_detail_nodes
    ]
    return TrackingDetails(
        carrier_name=settings.carrier_name,
        carrier_id=settings.carrier_id,
        tracking_number=tracking.TrackInfoID,
        events=[
            TrackingEvent(
                code=str(event.EventCode),
                date=format_date(event.EventDate, "%B %d, %Y"),
                time=format_time(event.EventTime, "%H:%M %p"),
                description=event.ActionCode,
                location=", ".join([
                    location for location in [
                        event.EventCity,
                        event.EventState,
                        event.EventCountry,
                        str(event.EventZIPCode),
                    ] if location is not None
                ]),
            ) for event in details
        ],
    )
コード例 #2
0
ファイル: track.py プロジェクト: gitter-badger/purplship
def _extract_tracking(shipment_node: Element,
                      settings: Settings) -> TrackingDetails:
    track_detail = ShipmentType()
    track_detail.build(shipment_node)
    activity_nodes = shipment_node.xpath(".//*[local-name() = $name]",
                                         name="Activity")

    def build_activity(node) -> ActivityType:
        activity = ActivityType()
        activity.build(node)
        return activity

    activities: List[ActivityType] = list(map(build_activity, activity_nodes))
    return TrackingDetails(
        carrier_name=settings.carrier_name,
        carrier_id=settings.carrier_id,
        tracking_number=track_detail.InquiryNumber.Value,
        events=list(
            map(
                lambda a: TrackingEvent(
                    date=format_date(a.Date, "%Y%m%d"),
                    time=format_time(a.Time, "%H%M%S"),
                    code=a.Status.Code if a.Status else None,
                    location=(a.ActivityLocation.Address.City
                              if a.ActivityLocation and a.ActivityLocation.
                              Address else None),
                    description=a.Status.Description if a.Status else None,
                ),
                activities,
            )),
    )
コード例 #3
0
def _extract_tracking(
    info_node: Element, settings: Settings
) -> Optional[TrackingDetails]:
    info = AWBInfo()
    info.build(info_node)
    if info.ShipmentInfo is None:
        return None

    return TrackingDetails(
        carrier_name=settings.carrier_name,
        carrier_id=settings.carrier_id,
        tracking_number=info.AWBNumber,
        events=list(
            map(
                lambda e: TrackingEvent(
                    date=format_date(e.Date),
                    time=format_time(e.Time),
                    signatory=e.Signatory,
                    code=e.ServiceEvent.EventCode,
                    location=e.ServiceArea.Description,
                    description=e.ServiceEvent.Description,
                ),
                info.ShipmentInfo.ShipmentEvent,
            )
        ),
    )
コード例 #4
0
def _extract_pickup(response: Element, settings: Settings) -> PickupDetails:
    pickup = BookPUResponse()
    pickup.build(response)
    pickup_charge = (ChargeDetails(
        name="Pickup Charge",
        amount=decimal(pickup.PickupCharge),
        currency=pickup.CurrencyCode,
    ) if pickup.PickupCharge is not None else None)
    return PickupDetails(
        carrier_name=settings.carrier_name,
        carrier_id=settings.carrier_id,
        confirmation_number=str(pickup.ConfirmationNumber[0]),
        pickup_date=format_date(pickup.NextPickupDate),
        pickup_charge=pickup_charge,
        ready_time=format_time(pickup.ReadyByTime),
        closing_time=format_time(pickup.CallInTime),
    )
コード例 #5
0
ファイル: track.py プロジェクト: QwadwoNyamekye/purplship
def _extract_tracking(pin_summary_node: Element, settings: Settings) -> TrackingDetails:
    pin_summary_ = pin_summary()
    pin_summary_.build(pin_summary_node)
    return TrackingDetails(
        carrier_name=settings.carrier_name,
        carrier_id=settings.carrier_id,
        tracking_number=pin_summary_.pin,
        events=[
            TrackingEvent(
                date=format_date(pin_summary_.event_date_time, "%Y%m%d:%H%M%S"),
                time=format_time(pin_summary_.event_date_time, "%Y%m%d:%H%M%S"),
                signatory=pin_summary_.signatory_name,
                code=pin_summary_.event_type,
                location=pin_summary_.event_location,
                description=pin_summary_.event_description,
            )
        ],
    )
コード例 #6
0
def _extract_tracking(track_detail_node: Element,
                      settings: Settings) -> Optional[TrackingDetails]:
    track_detail = TrackDetail()
    track_detail.build(track_detail_node)
    if track_detail.Notification.Severity == "ERROR":
        return None
    return TrackingDetails(
        carrier_name=settings.carrier_name,
        carrier_id=settings.carrier_id,
        tracking_number=track_detail.TrackingNumber,
        events=list(
            map(
                lambda e: TrackingEvent(
                    date=format_date(e.Timestamp, "%Y-%m-%d %H:%M:%S%z"),
                    time=format_time(e.Timestamp, "%Y-%m-%d %H:%M:%S%z"),
                    code=e.EventType,
                    location=e.ArrivalLocation,
                    description=e.EventDescription,
                ),
                track_detail.Events,
            )),
    )