Beispiel #1
0
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)
Beispiel #2
0
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
Beispiel #3
0
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

price_data = json.dumps(uber.get_price_estimate(start_latitude, start_longitude, end_latitude, end_longitude))
ride_data = json.loads(price_data)

all_rides = ride_data['prices']

for ride in all_rides:
    if ride['product_id'] == product_id:
        display_name = ride['display_name']
        price_estimate = ride['high_estimate']
#s.write("Olin College\nNeedham&")

tmp = 0
for i in xrange(output.count(' ')):
    tmp_old = tmp
    tmp = output.find(' ', tmp+1);
    if 12 < tmp < 17:
Beispiel #4
0
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']:
# 	low_estimate = fe['low_estimate']
# 	display_name = fe['display_name']
# 	print low_estimate
# 	print display_name
# 	print date

	# if display_name=='uberGO (Delhi to NCR)' or display_name=='uberX (Within Delhi)':
# 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]
start_long = Geocoder.geocode("180 Townsend Street, San Francisco, CA 94107")[0].coordinates[1]

end_lat = Geocoder.geocode("1737 Haight St, San Francisco, CA 94117")[0].coordinates[0]
end_long = Geocoder.geocode("1737 Haight St, San Francisco, CA 94117")[0].coordinates[1]

start_lat_test = Geocoder.geocode("poop").valid_address

print start_lat_test


estimate = AUTH.get_price_estimate(start_lat, start_long, end_lat, end_long)

print json.dumps(estimate, sort_keys=True, indent=4, separators=(',', ': '))

print estimate["prices"][0]["estimate"]