Esempio n. 1
0
def create_rests():
	results = app.query_yelp(15221)
	restaurants = db['restaurants']
	restaurants.remove({})
	app.add_to_db(results, restaurants)
	results = app.query_yelp(15213)
	app.add_to_db(results, restaurants)
Esempio n. 2
0
def explore(user_id):
	users = db['users']
	restaurants = db['restaurants']
	user = users.find({'_id': user_id})[0]
	user_coords = user['loc']
	dist = user['radius']
	zipcode = user['zip']
	city = user['city']

	# We need to call the Yelp API here to make sure we add anything we don't already have in our database - for now we'll just search by ZIP code
	results = app.query_yelp(zipcode)
	app.add_to_db(results, restaurants)

	# Find restaurants in user's city, then filter by distance based on user's location
	suggestions = restaurants.find({"city":city})
	# print user_coords
	# cur_user_address = Geocoder.reverse_geocode(user_coords[0], user_coords[1])
	# for rest in suggestions:
	# 	rest_ad = rest['address']
	# 	dist_in_meters = GoogleMaps.directions(cur_user_address, rest_ad)['Directions']['Distance']['meters']
	# 	dist_in_miles = 1.609*(float(dist_in_meters) / 1000.0) 
	# 	if dist_in_miles > dist:
	# 		suggestions.remove(rest)

	final_suggestions = []
	for s in suggestions:
		if s['name'] not in user['seen']:
			final_suggestions.append(s)

	print "Printing suggestions for user " + str(user_id)
	for s in final_suggestions:
		user['seen'].append(s['name'])
		print s['name']
	
	users.save(user)