Wrangling the Zomato API

The restaurant data work began with acquiring spreadsheet files for the restaurants, convenience stores, fast food restaurants, sweet and treats shops, and specialty food stores from the University of Ottawa's Ottawa Neighbourhood Study (ONS). From there Candide compiled all of the restaurant files into one spreadsheet and sent them to Lori. 

Zomato API Call (screen capture of code)

The Zomato API was a useful tool we used to extract data on restaurants in Ottawa such as their cuisine types and addresses, without having to manually go through Zomato, Yelp, TripAdvisor etc. to find all the restaurants in Ottawa that serve ethnic food. This also helped minimize the manual work to find the restaurant cuisine types. 

To make the Zomato API call, Lori had to generate an API key through their website. An API key is basically a code that allows you to authenticate yourself to be able to use the Zomato API. Once we generated an API key, we began writing a Python script to extract all the restaurants in Ottawa, along with all the attributes that Zomato has about that restaurant. In order to pull restuarant data across Ottawa, we had to make sure the script set the location attribute to all areas of Ottawa that are identified in Zomato: Ottawa East, Ottawa West, Ottawa Central and Ottawa South. 

Lori used the following line of code to search the Zomato database based on the attribute values specified:

Zomato_API ="https://developers.zomato.com/api/v2.1/search?entity_id=94138&entity_type=zone&start="+str(start)+"&count="+str(count)+"&lat=45.46986607392&lon=-75.37735539688"

In this call, she was able to retrieve restaurant data in the Ottawa Central zone (indicated using the entity_id, entity_type, lat, and lon attributes). Zomato also has a start and count attribute. The start attribute indicates at which line in the database you will start pulling data from. The count attribute is the number of lines each call will extract.

The only limitation we faced using Zomato’s API was that it only extracts 20 restaurants per call. We were able to solve this easily by modifying the script to continue looping until the API call stopped producing data. Our script then compiled all the data into a single JSON file. To make it easier to compile and clean the data, we used OpenRefine to convert the JSON file to CSV.  

Dataset of Ethnic Restaurants in Ottawa

Lori then merged both the Zomato and ONS datasets, and did a preliminary removal of entries that were fast food chains. From there, Lori, Liam, and I proceeded to the data cleaning to remove restaurants with Canadian and American cuisine types, add missing cuisine types, fix names and addresses, and add the associated continent(s) for each restaurant. During this process, if I found an interesting article about a restaurant owner who was an immigrant, I would forward it to the Research Team.

Afterwards, Lori separated the cleaned restaurant list by continent, and she and Candide uploaded the datasets to their respective ArcGIS map.

All of the maps for ethnic cuisine in Ottawa can be access through ArcGIS online: