Tracker script
This commit is contained in:
parent
d074e094eb
commit
00fcf7e9bb
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
from time import sleep
|
||||
from urbantz import Delivery
|
||||
from urbantz.exceptions import APIError
|
||||
from requests.exceptions import HTTPError
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Simple UrbanTZ delivery tracker",
|
||||
)
|
||||
parser.add_argument(
|
||||
'delivery',
|
||||
type=Delivery,
|
||||
metavar='ID',
|
||||
help='A unique UrbanTZ delivery ID',
|
||||
)
|
||||
options = parser.parse_args()
|
||||
delivery = options['delivery']
|
||||
|
||||
while True:
|
||||
try:
|
||||
delivery.update()
|
||||
except (APIError, HTTPError) as e:
|
||||
if isinstance(e, APIError) and e.code == 1:
|
||||
raise SystemExit('Invalid delivery ID')
|
||||
print('Error while fetching data:', str(e))
|
||||
|
||||
print("{} {} meters".format(
|
||||
delivery.last_updated.isoformat(),
|
||||
round(delivery.position.distance(delivery.destination), 1)
|
||||
))
|
||||
sleep(10)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue