- Created By: Marc Brittain
The function of this tool is to use the improve upon the already built YELP API package. In creating this tool, I followed the recommended advice from the YELP website which suggested to store your personal API key and information in a seperate file and to then call the file itself. The functions are built assuming one has stored the API information as recommended from YELP. These particular functions are made for accessing restaurant information for multiple cities. The max restaurants that can be returned for a given city is 1000, and note that YELP only allows 25,000 calls per day so the max amount of cities are 25. My goal was to create this easy-to-use package to help access the abundance of information on the YELP API. More analytical tools are currently in progress. Let's begin with a quick tutorial.
There are 3 modules that need to be installed to use this package:
- pandas module : allows the creation of dataframe which can be easily written out to excel files
- numpy module : useful when converting dataframes to arrays (should already be installed with python)
- YELP API : available on YELP's website. The tool to grab all of the raw information
To install, download the python file 'findCity.py' which contains all of the functions. From there you will need to create a seperate file in the same directory where 'findCity' downloaded called 'config_secret.json'. This is where you will store your YELP API key that you obtain from their website. Below is how they recommend setting up the file itself.
{
"consumer_key": "your_consumer_key",
"consumer_secret": "your_consumer_secret",
"token": "your_token",
"token_secret": "your_token_secret"
}
After the file with your API information is set up, the next step is to run the script findCity, which contains all of the functions.
run findCity
This should only take a second to run the script. The main function in the script is called restaurant_ratings_city. What is returned from this function is a dataframe so if one wants to utilize the data, assign to a variable as shown below.
df = restaurant_ratings_city() # call the function and assign it to a variable 'df'
# then follow the prompt and hit enter
# this step may take a little while due to the fact that it is getting all of the information from the YELP server.
Enter City Names (comma separated, no spaces): Chicago,Miami,Austin
df.head() # now call the variable to see the information that it collected
# the .head() function returns only the first 5 entries to get a preview
Chicago Restaurants | Chicago Ratings | Chicago Phone Number | Miami Restaurants | Miami Ratings | Miami Phone Number | Austin Restaurants | Austin Ratings | Austin Phone Number | |
---|---|---|---|---|---|---|---|---|---|
0 | Frank and Mary's Tavern | 4.5 | 7734638179 | Cardon Y El Tirano | 5.0 | 3053921257 | Baretto | 4.5 | 5123457994 |
1 | The Crab Pad | 4.5 | 7733608332 | Doce Provisions | 4.5 | 7864520161 | Blue Moon Bar & Grill | 3.5 | 5129169951 |
2 | Giant | 4.5 | 7732520997 | Glass & Vine | 4.0 | 3052005268 | Coast Bar & Kitchen | 4.5 | 5124674621 |
3 | Pub Royale | 4.0 | 7736616874 | Red Carpet Italian | 5.0 | 3055294220 | Boteco | 5.0 | None |
4 | Aloha Poke Co | 4.0 | None | Diced | 4.5 | 7867732190 | Hey!... You Gonna Eat or What? | 4.5 | 5122963547 |
df.tail() # let's see how many restaurants it returned
# the .tail() function returns the last 5 entries
Chicago Restaurants | Chicago Ratings | Chicago Phone Number | Miami Restaurants | Miami Ratings | Miami Phone Number | Austin Restaurants | Austin Ratings | Austin Phone Number | |
---|---|---|---|---|---|---|---|---|---|
995 | Valois | 4.0 | 7736670647 | Chez Le Bebe | 3.5 | 3057517639 | Downtown Jo's Coffee Shop | 3.5 | 5124699003 |
996 | Beef & Burger | 4.0 | 7736854960 | El Tambo Grill | 3.5 | 7867099943 | Caffe Yolly | 4.5 | 5124685575 |
997 | La Casa De Samuel | 3.5 | 7733767474 | Ceviche & Grill | 4.0 | 3052286072 | Danny's BBQ | 4.5 | None |
998 | Mr. B's BBQ | 4.0 | 7738801100 | Charcoals Latin Grill | 3.5 | 3054630209 | Heros Gyros | 4.5 | 5124689735 |
999 | Smoke Daddy | 3.5 | 7737726656 | Luis Galindo's Latin American 2 | 3.5 | 3052277002 | Giovanni's Pizza Stand | 4.5 | 5124427033 |
We can now see that we have 3,000 restaurants with their YELP rating, phone number, and name. If one wants to have all of this information in an excel workbook, just execute the line of code below and it will be formatted just like the dataframe.
df.to_excel('title_of_excel_file.xlsx')