Skip to content

Instantly share code, notes, and snippets.

@SteveCooling
Created April 3, 2018 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveCooling/3e9915bccdc8000fa0e64915d0891ea1 to your computer and use it in GitHub Desktop.
Save SteveCooling/3e9915bccdc8000fa0e64915d0891ea1 to your computer and use it in GitHub Desktop.
Simple text utility to track one or more shipments using Bring API (bring.com)
#!/usr/bin/env python3
#
# Simple text utility to track one or more shipments using Bring API (bring.com).
# Morten Johansen <morten@bzzt.no>
import sys
import requests
items = sys.argv
program = items.pop(0) # remove the program name
def statusToEmoji(status):
if status == 'ARRIVED_DELIVERY':
return '🏀'
elif status == 'CUSTOMS':
return 'πŸ›ƒ'
elif status == 'COLLECTED':
return 'βœ…'
elif status == 'DELIVERED':
return 'βœ…'
elif status == 'DELIVERED_SENDER':
return 'πŸ™'
elif status == 'DELIVERY_CANCELLED':
return 'βœ…'
elif status == 'DELIVERY_CHANGED':
return 'πŸ˜•'
elif status == 'DELIVERY_ORDERED':
return 'βœ…'
elif status == 'DEVIATION':
return 'πŸ™'
elif status == 'HANDED_IN':
return 'πŸ“₯'
elif status == 'INTERNATIONAL':
return '🌍'
elif status == 'IN_TRANSIT':
return '🚚'
elif status == 'NOTIFICATION_SENT':
return 'πŸ“²'
elif status == 'PRE_NOTIFIED':
return 'πŸ—’'
elif status == 'READY_FOR_PICKUP':
return '🏀'
elif status == 'RETURN':
return 'πŸ™'
elif status == 'TRANSPORT_TO_RECIPIENT':
return '🚚'
else:
return '❓'
s = requests.session()
if len(items) > 0:
for i in items:
r = s.get('https://tracking.bring.com/api/tracking.json', params={'q': i})
#print(r.json())
try:
for cs in r.json()['consignmentSet']:
#print(cs)
for ps in cs['packageSet']:
print("%s %s\n %-20s, %-20s %s %s\n" % (
'πŸ“¦',
ps['packageNumber'],
ps['eventSet'][0]['city'],
ps['eventSet'][0]['country'],
statusToEmoji(ps['eventSet'][0]['status']),
ps['eventSet'][0]['description'],
))
except KeyError:
print("❓ %s\n NO INFORMATION\n" % i)
else:
print("Usage: %s [trackingno1] [trackingno2] ..." % program)
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment