Example #1
0
def find_restaurants(address, cuisine, walk_time, inspection, rating=None):
    '''
    Takes parameters and searches for restaurants matching the search criteria.
    Returns a tuple with a header and a list of tuples representing restaurants
    This code uses sqlite3 to search the yelp table and healthfails table
    '''

    #creates the database using yelp_search in yelpapi
    yelpapi.yelp_search(address, cuisine)
    connection_yelp = sqlite3.connect("yelp_database")
    db = connection_yelp.cursor()
    header = []

    #creates header in the form of a row in the Food_Search return value
    header_list = ['Restaurants', 'Address', 'Rating', 'Phone', 'Walking Time']
    for i in range(len(header_list)):
        header.append((header_list[i], False))
    
    #sqlite 3 search strings initialization
    selectline = 'SELECT yelp_results.name, yelp_results.address, yelp_results.rating, yelp_results.phone_number, yelp_results.walking_time'
    fromline = ' FROM yelp_results'
    whereline = ' WHERE yelp_results.walking_time < ?'
    
    #adds to sqlite3 search strings as necesary if inspection
    if inspection:
        selectline += ', healthfails.Risk'
        header.append(('Risk', False))
        fromline += ' LEFT OUTER JOIN healthfails ON yelp_results.address=healthfails.Address COLLATE NOCASE'

    #creates end_list (we are always searching for walk_time)
    end_list = [walk_time]

    #appends to lines and end_list as necesary if rating parameter
    if not rating == None:
        whereline += ' and yelp_results.rating >= ?'
        end_list.append(rating)

    #executes the search, drops the table and closes the database
    r = db.execute(selectline + fromline + whereline + ';', end_list)
    tuple_list = r.fetchall()
    yelpapi.drop_yelp_table("yelp_results")
    db.close()

    return (header,tuple_list)
Example #2
0
def find_food_trucks(address, cuisine, walking_time, rating = None):
    '''
    Takes parameters and searches for foodtrucks matching the search criteria.
    Returns a tuple with a header and a list of tuples representing restaurants
    This code uses sqlite3 to search the yelp food truck table
    '''
    #calls yelp_search_food_trucks in yelpapi
    yelpapi.yelp_search_food_trucks(address, cuisine)
    connection_yelp = sqlite3.connect("yelp_database")
    db = connection_yelp.cursor()

    #constructs the header row as required in Food_search
    header = []
    header_list = ['Food Trucks', 'Rating', 'Phone', 'Arrive Time', 'Depart Time']
    for i in range(len(header_list)):
        header.append((header_list[i], False))

    #initializes the sqlite3 search strings
    selectline = 'SELECT yelp_food_trucks.name, yelp_food_trucks.rating, yelp_food_trucks.phone_number, yelp_food_trucks.arrive_time, yelp_food_trucks.leave_time'
    fromline = ' FROM yelp_food_trucks'
    whereline = ' WHERE yelp_food_trucks.walking_time < ?'
    
    #initializes end_list
    end_list = [walking_time]

    #handles the case of searching for a specific rating
    if not rating == None:
        whereline += ' and yelp_food_trucks.rating >= ?'
        end_list.append(rating)

    #does the sqlite3 search and returns, closes the database and drops the table
    r=db.execute(selectline + fromline + whereline + ';', end_list)
    tuple_list = r.fetchall()
    db.close()
    yelpapi.drop_yelp_table("yelp_food_trucks")

    return (header, tuple_list)
Example #3
0
def drop():
    '''
    This code was only used for testing, drops the table yelp_results. 
    '''
    yelpapi.drop_yelp_table("yelp_results")