Now You Code In Class: Where Can I Get Something to Eat?

Let's write an application which uses the Zomato api https://developers.zomato.com/api to provide access to local area restaurants.

The basic gist of the application will be:

  1. ask for a location
  2. ask for the type of cuisine you are interested in
  3. output restaurant suggestions
  4. when one is selected display the address and phone number.

You should try to implement the following functions below. I suggest taking a bottom-up problem solving approach, first writing the function, testing it, and then finally using them in the main program. Remember good functions should do one thing well and have data inputs and data outputs through the return statement. They should be immutable, meaning the function does not change data but instead it returns the data back to the caller.

Once you implement the functions, implement your main program. Then implement any error handling.

Step 1: Problem Analysis

Inputs:

Outputs:

Algorithm (Steps in Program):


In [1]:
import requests 

zomato_key = 'EnterYourKeyHere'

def get_city_id(zomato_key, city_state):
    '''
        returns the first city_id in the search results, None when there are no results.
        return city_id 
    '''
    # todo: implement here
    

def search_area(zomato_key, city_id, keywords):
    '''
        returns a list of restaurants in the city_id matching keywords
        return list of restaurants 
    '''
    # todo: implement here

def restaurant_details(zomato_key, rest_id):
    '''
        returns a details of a restaurant given the rest_id 
        return on success: {'status' : 'ok', 'message' : 'ok', 'details' : details }
        return on failure: {'status' : 'error', 'message' : 'Reason for failure.', 'details' : None }
    '''
    # todo: implement here

    
    
# MAIN

In [15]:


In [ ]: