コード例 #1
0
ファイル: yelp_api.py プロジェクト: ashleylorden/foodboom
    def search_similar_restaurants(self, restaurant, lat_lon=None, bearing=None):
        #  rest not closed, matching cats, limit 15
        if not lat_lon:
            lat_lon = '37.7872247,-122.39926'
        lat, lon = lat_lon.split(',')
        if not bearing:
            results = yelp_request(
                'search',
                {
                    'term': 'restaurant',
                    'limit': 15,
                    'category_filter': restaurant.get_categories().lower(),
                    'sort': 1,
                    'll': lat_lon,
                },
                self.consumer_key,
                self.consumer_secret,
                self.token,
                self.token_secret
            )
        else:
            lat1, lon1, lat2, lon2 = get_yelp_coordinates(lat, lon, bearing, 2)
            # lat2, lon2 = pointRadialDistance(lat, lon, bearing, 5.8)
            print "L1: %s" % lat_lon
            print "L2: %s,%s" % (lat2, lon2)
            results = yelp_request(
                'search',
                {
                    'term': 'restaurant',
                    'limit': 15,
                    'category_filter': restaurant.get_categories().lower(),
                    'sort': 1,
                    'bounds': "%s,%s|%s,%s" % (lat1, lon1, lat2 ,lon2)
                },
                self.consumer_key,
                self.consumer_secret,
                self.token,
                self.token_secret
            )

        # Put them on a list except the closed ones
        restaurants = []
        if not results.get('businesses'):
            return []
        for result in results.get('businesses', None):
            if not result.get('is_closed') and \
                    result.get('id') != restaurant.yelp_id:
                r = Restaurant()
                r.load_data(result)
                restaurants.append(r)

        # Sort by rating
        restaurants = sorted(restaurants, key=lambda r: r.rating, reverse=True)

        # Keep top 3
        restaurants = restaurants[1:4]

        return restaurants
コード例 #2
0
ファイル: yelp_api.py プロジェクト: ashleylorden/foodboom
 def get_restaurant(self, restaurant_id):
     result = yelp_request(
         'business',
         {'id': restaurant_id},
         self.consumer_key,
         self.consumer_secret,
         self.token,
         self.token_secret
     )
     restaurant = Restaurant()
     restaurant.load_data(result)
     return restaurant
コード例 #3
0
ファイル: yelp_api.py プロジェクト: ashleylorden/foodboom
    def search_restaurant(self, string):
        results = yelp_request(
            'search',
            {
                'term': string,
                'location': 'San Francisco',
                'category_filter': 'restaurants',
                'limit': 5
            },
            self.consumer_key,
            self.consumer_secret,
            self.token,
            self.token_secret
        )

        restaurants = []
        for result in results.get('businesses', None):
            r = Restaurant()
            r.load_data(result)
            restaurants.append(r)
        return restaurants