def search_by_bounding_box( self, sw_latitude, sw_longitude, ne_latitude, ne_longitude, **url_params ): """Make a request to the search endpoint by bounding box. Specify a southwest latitude/longitude and a northeast latitude/longitude. See http://www.yelp.com/developers/documentation/v2/search_api#searchGBB Args: sw_latitude (float): Southwest latitude of bounding box. sw_longitude (float): Southwest longitude of bounding box. ne_latitude (float): Northeast latitude of bounding box. ne_longitude (float): Northeast longitude of bounding box. **url_params: Dict corresponding to search API params https://www.yelp.ca/developers/documentation/v2/search_api#searchGP Returns: SearchResponse object that wraps the response. """ url_params['bounds'] = self._format_bounds( sw_latitude, sw_longitude, ne_latitude, ne_longitude ) return SearchResponse(self._make_request(SEARCH_PATH, url_params))
def call_API(self): # return self.client.search('SF', self.data) # return SearchResponse ( # self.client._make_request(SEARCH_PATH, self.data) # ) response = SearchResponse( self.client._make_request(SEARCH_PATH, self.data) ) list_to_be_returned = [] # for bus in response.businesses: # list_to_be_returned += Crawler.limit("http://www.yelp.com/biz_photos/" + bus.id + "?tab=food&start=0", self.food_per_business) dict_of_urls = {} for bus in response.businesses: # pprint(vars(bus)) # pprint(bus.categories[0].name) # pprint(vars(bus.location.coordinate)) url = "http://www.yelp.com/biz_photos/"+bus.id+"?tab=food&start=0" # list_of_urls.append({url: [bus.location, bus.name]}) # list_of_urls.append({url: category_list = [] for category in bus.categories: category_list.append(category.name) dict_of_urls= dict(address=bus.location.address, restaurant_name=bus.name, restaurantId = bus.id, city=bus.location.city, state=bus.location.state_code, postal_code=bus.location.postal_code, display_address=bus.location.display_address, latitude=bus.location.coordinate.latitude, longitude=bus.location.coordinate.longitude, category=category_list ) list_to_be_returned.append(dict_of_urls) # print dict_of_urls # pprint(list_of_urls) # print (list_of_urls) # Crawler.limit(list_of_urls, 1) # return Crawler(dict_of_urls).limit(self.food_per_business) # return dict_of_urls return list_to_be_returned
def phone_search(self, phone, **url_params): """Make a request to the phone search endpoint.More info at https://www.yelp.com/developers/documentation/v2/phone_search Args: phone (str): Business phone number to search for. **url_params: Dict corresponding to phone search API params https://www.yelp.com/developers/documentation/v2/phone_search Returns: SearchResponse object that wraps the response. """ url_params['phone'] = phone return SearchResponse( self._make_request(PHONE_SEARCH_PATH, url_params) )
def call_API(self): response = SearchResponse( self.client._make_request(SEARCH_PATH, self.data)) dict_of_urls = {} for bus in response.businesses: # url = "http://www.yelp.com/biz_photos/"+bus.id+"?tab=food&start=0" category_list = [] if bus.categories: for category in bus.categories: category_list.append(category.name) dict_of_urls[bus.id] = dict( address=bus.location.address, city=bus.location.city, state=bus.location.state_code, postal_code=bus.location.postal_code, display_address=bus.location.display_address, restaurant_name=bus.name, restaurantId=bus.id, latitude=bus.location.coordinate.latitude, longitude=bus.location.coordinate.longitude, category=category_list) print(vars(response)) if response.total == 0: raise RuntimeError("Yelp returns no businesses") if 'query_method' in self.data and self.data['query_method'] == 1: print("DB") food_list = DB(dict_of_urls).query(self.food_per_business) else: print("Yelp") food_list = Crawler(dict_of_urls).query(self.food_per_business) random.shuffle(food_list) return food_list