Esempio n. 1
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)
Esempio n. 2
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. 3
0
    def test_success(self):
        for test in self.success_test_params:
            with patch('app.DB.session.add', self.mocked_db_session_add):
                with patch('app.DB.session.commit',
                           self.mocked_db_session_commit):

                    data = [
                        test[KEY_EMAIL], test[KEY_INPUT], test[KEY_IMAGE_URL]
                    ]
                    add_to_db(data)

                    actual_result = str(self.initial_db_mock)

                    expected_result = test[KEY_EXPECTED]

                    self.assertEqual(len(actual_result), len(expected_result))
                    self.assertEqual(actual_result, expected_result)