Ejemplo n.º 1
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 + "'")
Ejemplo n.º 2
0
    LUNCH,
    ATTRACTION,
    DINNER,
    NIGHTLIFE
]

# ranges (inclusive) are non-overlapping to simplify sample generation
CATEGORY_START_HOURS = {
    BREAKFAST: (8, 10),
    LUNCH: (12, 13),
    ATTRACTION: (14, 17),
    DINNER: (18, 20),
    NIGHTLIFE: (21, 22)
}

CATEGORIES = [model.match_category(name) for name in DEFAULT_SCHEDULE]

FETCH_STRATEGY_OPTIONS = ['distance', 'yelp-rating'] + strategy.STRATEGIES.keys()


def new_fetch_sample_itinerary(user, name, city, start_time, end_time, date, public):
    """
    start_time, end_time, and date should be STRINGS straight from args[]
    (i.e. don't pass datetime object result of dateutil.parser.parse)

    Does not persist itinerary to DB!
    """
    valid_categories = filter_valid_categories(CATEGORIES, start_time, end_time)

    candidate_items_groupby_category = []
    for category in valid_categories: