car = int(s.readline().strip('\r\n')) car_types = {0:'uberX',1:'uberXL',2:'UberBLACK'} return car_types[car] def get_loc(): sr = SpeechRecog() return sr.speechToCoord() # Trip location data start_latitude, start_longitude = (42.347097, -71.097011) # end_latitude, end_longitude = (42.291641, -71.264653) uber = Uber(client_id, server_token, client_secret) time_data = json.dumps(uber.get_time_estimate(start_latitude, start_longitude)) time_estimate = json.loads(time_data)['times'] def get_time_estimate(car_type): product_id = None for car in time_estimate: if car['display_name'] == car_type: product_id = car['product_id'] waiting_estimate = car['estimate'] break return (product_id, waiting_estimate) product_id, waiting_estimate = get_time_estimate(get_car_type()) end_latitude, end_longitude,output = get_loc() print output
#locations list #get locations from database db = sqlite3.connect('/home/dan/projects/uber_eta/FlaskApp/database.sqlite3') cursor = db.cursor() cursor.execute('''select location_name,lattitude,longitude from locations''' ) for row in cursor: location = row[0] latitude = row[1] longitude = row[2] #build up API call to get products uber = Uber(client_id, server_token, secret) products = uber.get_products(latitude, longitude) #Get Product ID for product in products['products']: if product['display_name'] == 'uberX': product_id = product['product_id'] #Get ETA for product try: time_estimate = uber.get_time_estimate(latitude, longitude, customer_uuid=None, product_id=product_id) time_estimate = time_estimate['times'][0]['estimate'] except: print "error obtaining data" #get current time current_time = datetime.now() cursor = db.cursor() cursor.execute("INSERT INTO " + location + " (datetime, eta) VALUES(\"%s\", %s)" %(current_time, time_estimate)) db.commit() db.close() sys.exit()