Add destination information
This commit is contained in:
parent
0023cd7292
commit
9c1d438eb1
|
@ -8,6 +8,19 @@ import requests
|
||||||
DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
|
DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
|
||||||
|
|
||||||
|
|
||||||
|
class Location(DictObject):
|
||||||
|
"""
|
||||||
|
A delivery destination.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
if 'location' not in self:
|
||||||
|
return
|
||||||
|
point = self.pop('location')['geometry']
|
||||||
|
self['coordinates'] = Coordinates.fromJSON(point)
|
||||||
|
|
||||||
|
|
||||||
class Delivery(JSONSerializable):
|
class Delivery(JSONSerializable):
|
||||||
"""
|
"""
|
||||||
A UrbanTZ delivery with a unique ID.
|
A UrbanTZ delivery with a unique ID.
|
||||||
|
@ -141,9 +154,9 @@ class Delivery(JSONSerializable):
|
||||||
|
|
||||||
self.destination = None
|
self.destination = None
|
||||||
"""
|
"""
|
||||||
Coordinates of the delivery destination.
|
The delivery's destination.
|
||||||
|
|
||||||
:type: urbantz.base.Coordinates or None
|
:type: urbantz.delivery.Location or None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.recipient = None
|
self.recipient = None
|
||||||
|
@ -290,8 +303,7 @@ class Delivery(JSONSerializable):
|
||||||
]
|
]
|
||||||
|
|
||||||
self.position = Coordinates.fromJSON(self.payload['position'])
|
self.position = Coordinates.fromJSON(self.payload['position'])
|
||||||
self.destination = Coordinates.fromJSON(
|
self.destination = Location.fromJSON(self.payload['location'])
|
||||||
self.payload['location']['location']['geometry'])
|
|
||||||
self.recipient = DictObject(self.payload['contact'])
|
self.recipient = DictObject(self.payload['contact'])
|
||||||
self.features = DictObject(self.payload['features'])
|
self.features = DictObject(self.payload['features'])
|
||||||
self.template = DictObject(self.payload['template'])
|
self.template = DictObject(self.payload['template'])
|
||||||
|
|
|
@ -33,9 +33,10 @@ def main():
|
||||||
raise SystemExit('Invalid delivery ID')
|
raise SystemExit('Invalid delivery ID')
|
||||||
print('Error while fetching data:', str(e))
|
print('Error while fetching data:', str(e))
|
||||||
|
|
||||||
|
distance = delivery.position.distance(delivery.destination.coordinates)
|
||||||
print("{} {} meters".format(
|
print("{} {} meters".format(
|
||||||
delivery.last_updated.isoformat(),
|
delivery.last_updated.isoformat(),
|
||||||
round(delivery.position.distance(delivery.destination), 1),
|
round(distance, 1),
|
||||||
))
|
))
|
||||||
sleep(options['frequency'])
|
sleep(options['frequency'])
|
||||||
|
|
||||||
|
|
Reference in New Issue