The Urban Dictionary is an amazing resource for english language lovers; It features accurate definitions of words, not like other services like Wikipedia, Oxford, etc. 😅
In this project, you are going to build a terminal based (CLI) dictionary.
- Register a RapidAPI.com account and make your to request a key for the urban dictionary API.
- Watch this 15 min video to understand pipenv, the python package manager.
- Watch this 10 min video on what are API Keys and credentials.
Clone this repository locally (git clone <project url>
) or open it with Gitpod by clicking here (recomended):
Note: The project requires Python 3.8 and pipenv (python package manager), if you open it with Gitpod you are ok but localhost users will need to install it manually.
Install the application dependencies by typing (only once):
$ pipenv install
Run the application by typing (every time):
$ pipenv run python app.py
- Greet the user
- Ask the user for the term he/she wants to look up, use the
input("What term do you want to look for?")
python function. - Use the python requests package to code your GET request to the Urban Dictionary API
Let's suppose that we are looking for the definition of the word computer
The API specification says that you have to do a GET request to the following URL:
url = "https://mashape-community-urban-dictionary.p.rapidapi.com/define?term=computer"
Don't forget to add the headers
with the API credentials, please refer to the API example in the documentation.
- Process the response body, understand it, and get the word definition from the incoming response body.
- Show the definition on the terminal.
- Store the definition in a JSON file.
The following requirements are not mandatory, but you can try completing them if you feel confident:
- Cache system: If the user asks for the same word again, instead of calling the API again, you should have the previous responses stored in a
dict
. - Look for multiple words separated by comma.
- Use
sys.argv
to allow the user to ask for a definition like this:
# "enjoy" is the word the user is looking up the definition
$ pipenv run python app.py enjoy
Hint: how to use the sys.argv