Esempio n. 1
0
def get_yelp_item(coordinate, category, strategy=DistanceStrategy()):
    extra_yelp_params = {}
    yelp_item_repository = YelpItemRepository()

    # for these strategies, use YelpAPI
    # then reset strategy_name so that we can still call strategy module below
    extra_yelp_params['radius_filters'] = 7500

    if strategy.type == StrategyType.popularity:
        extra_yelp_params['sort'] = 2
        strategy = FirstStrategy()
    elif strategy.type == StrategyType.distance:
        extra_yelp_params['sort'] = 1
        strategy = FirstRandomStrategy()

    try:
        search_results = query(yelpapi.search(coordinate.latitude,
                                              coordinate.longitude,
                                              category.search_term,
                                              query(category.search_filters).select(lambda f: f.filter).to_list(),
                                              **extra_yelp_params)).where(
            lambda r: ['Food Trucks', 'foodtrucks'] not in r['categories'])
        yelp_items = [YelpItem.create_from_dict(result) for result in search_results]
        yelp_item = strategy.run_strategy(yelp_items)
        yelp_item = yelp_item_repository.get_or_insert(yelp_item)
        yelp_item_repository.save_changes()
        return yelp_item
    except:
        return None
Esempio n. 2
0
 def get(self, **kwargs):
     args = self.parser.parse_args()
     search_results = yelpapi.search(args.latitude, args.longtitude, 
                           args.term,args.categories.split(','),**kwargs)
     yelp_items = [YelpItem.create_from_dict(result) for result in search_results]
     return yelp_items