client_id = '' server_token = '' secret = '' #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))
import json import working from uberpy import Uber from pygeocoder import Geocoder # Creates a new Uber instance using tokens AUTH = Uber(working.client_id, working.server_token, working.secret) # print AUTH latitude = 51.5286416 longitude = -0.1015987 uber_products = AUTH.get_products(latitude, longitude) # Prints JSON object in a format that won't make you insane print json.dumps(uber_products, sort_keys=True, indent=4, separators=(',', ': ')) ### This is a fix for the problem that arose from the geocode lbirary, fixes SSL restrictions. See site for more details: https://urllib3.readthedocs.org/en/latest/security.html#pyopenssl # try: # import urllib3.contrib.pyopenssl # urllib3.contrib.pyopenssl.inject_into_urllib3() # except ImportError: # pass ### start_lat = Geocoder.geocode("180 Townsend Street, San Francisco, CA 94107")[0].coordinates[0]