def determine_estimate(): ### Gets addresses, converts them to coordinates, requests estimates from API, creates dictionary, saves to a session to use later uber_prices = [] app_start_address = request.args.get('start_address') app_end_address = request.args.get('end_address') ### 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 ### If the server receives correct input, it will convert to coordinates, make reuqest from Uber API, if not it will display an error message try: if Geocoder.geocode(app_start_address).valid_address and Geocoder.geocode(app_end_address).valid_address is True: start_lat = Geocoder.geocode(app_start_address)[0].coordinates[0] start_long = Geocoder.geocode(app_start_address)[0].coordinates[1] end_lat = Geocoder.geocode(app_end_address)[0].coordinates[0] end_long = Geocoder.geocode(app_end_address)[0].coordinates[1] AUTH = Uber(ENV.CLIENT_ID, ENV.SERVER_TOKEN, ENV.SECRET) estimate = AUTH.get_price_estimate(start_lat, start_long, end_lat, end_long) services_and_prices = estimate['prices'] for i in range(len(services_and_prices)): uber_price = {} uber_price['service'] = services_and_prices[i]['display_name'] uber_price['price'] = services_and_prices[i]['estimate'] uber_prices.append(uber_price) session['user_travel'] = uber_prices return render_template("results.html") else: message = "Something went wrong. Please make sure you entered valid addresses." return render_template("index.html", message=message) except: message = "Something went wrong. Please make sure you entered valid addresses." return render_template("index.html", message=message)
def uber_json(xid,listings,id_rowidx,B): xid=9062929 xrow=idrowidx[xid] k=min(len(B)/10,20) top20=B.sort(['review_scores_value'],ascending=False).index[0:k] near=B.loc[top20] doc_id=[i for i in near.index] doc_id[-1]=xrow tfidf=vect.fit_transform(list(listings['description'][doc_id])) #print pd.DataFrame((tfidf * tfidf.T).A)[19] arr = pd.DataFrame((tfidf * tfidf.T).A)[19] argmax=arr.argsort()[-len(arr):][::-1] similar_id={} listings['uber']=0 uber = Uber('uHcGyypDvCoajjhhx-cyTdcnpZzbQV9j', 'V320Y_XH3wStYXbNGaqgoUV1dGX84eYfJfaCHNXS','GxoruYkFBi_kKaCYwYnILL_45UuVE729e5ohN7wW') for x in argmax: raw_row=doc_id[x] lon=listings['longitude'][raw_row] lat=listings['latitude'][raw_row] end_lon =listings['longitude'][xrow] end_lat =listings['latitude'][xrow] fare_estimate = uber.get_price_estimate(lat,lon, end_lat,end_lon) uberfare=fare_estimate['prices'][0]['low_estimate']*2 totalfare=listings['price'][raw_row]+uberfare if totalfare<price: similar_id[raw_row]=uberfare print(raw_row) listings['uber'][raw_row]=uberfare if len(similar_id)==5: break sim_id=similar_id.keys() temp=listings.loc[sim_id] ttemp=temp[['id','longitude','latitude','name','summary','price','uber']] dtemp= [ dict([ (colname, row[i]) for i,colname in enumerate(ttemp.columns) ]) for row in ttemp.values ] return dtemp
def get_car_type(): 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())
#Build Uber instance 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()
from uberpy import Uber import pprint import MySQLdb import time con = MySQLdb.connect('localhost','root','','uber') client_id ='hlbRMlhkB8kxRBozHiRccnfIHv6fsJ5e' server_token = "2H26_n81qOVOJmafk_nRjUgMqepNCnWvIr4X9o1n" secret = '6YA8yP80GMtYbLYmZsY1oNI3fwlEEOObDiws-1-o' uber = Uber(client_id, server_token, secret) latitude = 51.5286416 longitude = -0.1015987 uber_products = uber.get_products(latitude, longitude) # pprint.pprint(uber_products) start_latitude = '28.53544' start_longitude = '77.26393' end_latitude = '28.45950' end_longitude = '77.02664' # uber.get_fare_estimate # time_estimate = uber.get_time_estimate(start_latitude, start_longitude, customer_uuid=None, product_id=None) fare_estimate = uber.get_price_estimate(start_latitude, start_longitude, end_latitude, end_longitude) pprint.pprint(fare_estimate) date = str(time.strftime('%y/%m/%d')) price_go = [ fe['low_estimate'] for fe in fare_estimate['prices'] if fe['display_name']=='uberGO (Delhi to NCR)'][0] # print price_go price_x = [ fe['low_estimate'] for fe in fare_estimate['prices'] if fe['display_name']=='uberX (Within Delhi)'][0] # for fe in fare_estimate['prices']:
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]
messages = [ "Welcome to rideText! What would you like to do?", #"A 128-bit secured webpage will now open up, where you can enter your username and password", "Please type in an address or intersection", "Ubers available:", "Please type in a destination", "Uber is on the way! Text the keyword 'status' for the status of your uber" ] keywords = [ "request" "status", "cancel" ] uber = Uber("", "", "") geolocator = Nominatim() app = Flask(__name__) @app.route("/", methods=['GET', 'POST']) def hello(): global counter global address global destination global dest_coords global selected_uber global latitude global longitude resp = twilio.twiml.Response() response_details = request.values