-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
20 lines (19 loc) · 759 Bytes
/
dictionary.py
File metadata and controls
20 lines (19 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# https://rapidapi.com/community/api/urban-dictionary
import requests
import os
from dotenv import load_dotenv
load_dotenv()
def get_urban_dictionary_definition(term):
url = f"https://mashape-community-urban-dictionary.p.rapidapi.com/define?term={term}"
headers = {
"X-RapidAPI-Host": "mashape-community-urban-dictionary.p.rapidapi.com",
"X-RapidAPI-Key": os.getenv('env_X_RapidAPI_Key')
}
response = requests.get(url, headers=headers)
data = response.json()
if "list" in data:
if data["list"]:
definition = data["list"][0]["definition"]
example = data["list"][0]["example"]
return f"**Definition:** {definition}\n\n**Example:** {example}"
return "No definition found."