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:
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.
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 [ ]: