예제 #1
0
def candidate_yelp_ids_with_name(location, category):
    extra_yelp_params = {'radius_filters': 7500}
    search_results = yelpapi.search(category.search_term, location, category.filters, **extra_yelp_params)
    candidate_ids_with_names = [(result['id'], result['name'])
                                for result
                                in search_results]
    return candidate_ids_with_names
예제 #2
0
def cache_yelp_entries(city, category_name):
    category = model.match_category(category_name)

    log('\tYelpAPI: Search call for category ' + category_name)
    yelp_api_results = yelpapi.search(category.search_term, city, category.filters)

    log('\tYelpAPI: Making Business calls (and scraping for prices) and caching entries...')
    count = 0
    for api_result in yelp_api_results:
        if not db.sqlite.has_yelp_entry(api_result['id']):
            if len(api_result['location']['address']) > 0:
                log('\t\tcaching <' + api_result['url'] + '>')
                count += 1
                entry = yelpapi.business(api_result['id'])
                db.sqlite.insert_yelp_entry(entry)
            else:
                log('Could not cache: '+str(api_result))
        else:
            log('Already added: '+ api_result['id'])

    log("\t" + str(count) + " new yelp_entries for category '" + category_name + "'")
예제 #3
0
def best_yelp_id_with_name(location, category, coordinate_str=None, disallowed_yelp_ids=[], strategy_name="distance"):
    """coordinate_str is for cll param in query string"""
    extra_yelp_params = {}
    if coordinate_str is not None:
        extra_yelp_params['cll'] = coordinate_str

    # 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_name == 'yelp-rating':
        extra_yelp_params['sort'] = 2
        strategy_name = 'first'
    elif strategy_name == 'distance':
        extra_yelp_params['sort'] = 1
        strategy_name = 'first_random'

    search_results = yelpapi.search(category.search_term, location, category.filters, **extra_yelp_params)
    candidate_ids_with_names = [(result['id'], result['name'])
                                for result
                                in search_results
                                if result['id'] not in disallowed_yelp_ids]

    candidate_ids = [elem[0] for elem in candidate_ids_with_names]

    if len(candidate_ids_with_names) == 0:
        print "best_yelp_id_with_name: no good ids found!  returning random result"
        default_result = search_results[random.randrange(len(search_results))]
        return default_result['id'], default_result['name']

    index = strategy.run_strategy(strategy_name, candidate_ids)

    if index == -1:  # strategy found nothing
        index = 0

    yelp_id = candidate_ids_with_names[index][0]
    yelp_name = candidate_ids_with_names[index][1]
    return yelp_id, yelp_name