示例#1
0
    def get_yelp_entry(self, id):
        if not self.has_yelp_entry(id):
            entry = yelpapi.business(id)
            self.insert_yelp_entry(entry)

        with sqlite3.connect(self.db_name) as conn:
            cursor = conn.cursor()
            cursor.row_factory = self.yelp_entry_from_cursor
            cursor.execute(
                'SELECT * FROM {table} WHERE {id}=?'
                .format(
                    table=yelp_entry.YELP_ENTRY_TABLE,
                    id=yelp_entry.ID
                ),
                (id, )
            )
            entry = cursor.fetchone()
            cursor.close()
            return entry
示例#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 + "'")