Skip to content

Instantly share code, notes, and snippets.

@imryan
Last active July 4, 2017 20:30
Show Gist options
  • Save imryan/0891f2af0203a3b0e25d26ab01d19dce to your computer and use it in GitHub Desktop.
Save imryan/0891f2af0203a3b0e25d26ab01d19dce to your computer and use it in GitHub Desktop.
Insomnia cookies order tracker tool
# insomnia.py
# by Ryan Cohen
import urllib2
import json
import sys
FIRST_ORDER_ID = 5521566
START_ID = 5520000
MULTIPLIER = 10000
STATUS_URL = 'https://insomniacookies.com/tracker/getOrderStatus?order_id='
LOCATION_URL = 'https://insomniacookies.com/tracker/getDriverLocation/'
class Order:
def __init__(self, order, location, failed=False):
if failed:
self.order = json.loads(order)
else:
self.order = json.loads(order)[0]
self.location = location
def order_id(self):
return self.order.get('id') or None
def status(self):
return self.order.get('status') or -1
def driver_location():
return self.location if self.location else None
def description(self):
if self.status() == -1:
print '* Order not found'
print self.order
else:
print "* {0} -> {1} -> {2}".format(self.order_id(), self.parse_status(), self.location.description())
def parse_status(self):
status = self.status()
if status == None:
return 'Fresh'
status = int(status)
if status == 5:
return 'Delivered'
elif status == 4:
return 'Out for Delivery'
elif status == 3:
return 'Preparing'
elif status == 2:
return 'Processing'
return 'Unknown'
class Location:
def __init__(self, location):
self.location = json.loads(location)
try:
self.location = self.location['location']
except KeyError:
pass
def description(self):
if len(list(self.location)) == 0:
return 'None'
print self.location
return self.location['lat'] + ', ' + self.location['lng']
def request(order_id):
url = STATUS_URL + str(order_id)
response = str(urllib2.urlopen(url).read())
order_failed = (json.loads(response)['error'] == 1)
order = Order(response, get_location(order_id), failed=order_failed)
print order.description()
def get_location(order_id):
url = LOCATION_URL + str(order_id)
response = str(urllib2.urlopen(url).read())
location = Location(response)
return location
def main():
multiplier = MULTIPLIER
order_id = START_ID
if len(sys.argv) == 2:
multiplier = int(sys.argv[1])
while True:
order_id = order_id + multiplier
request(order_id)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment