-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal_dictionary.py
52 lines (37 loc) · 1.29 KB
/
terminal_dictionary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import pandas as pd
import requests
def get_definition(term):
url = "https://urban-dictionary7.p.rapidapi.com/v0/define"
querystring = {"term":term}
headers = {
"x-rapidapi-key": "066b666a77msh9bb357e6cfa4065p14c7ebjsn35b1d1cfb89d",
"x-rapidapi-host": "urban-dictionary7.p.rapidapi.com"
}
response = requests.get(url, headers=headers, params=querystring)
data=response.json()
if data['list']:
definition = data['list'][0]['definition']
example = data['list'][0]['example']
return definition, example
else:
print("No definition or example available. kindly enter a valid word!")
def main():
print("Welcome to your own terminal Dictionary: ")
print("Type 'exit' to quit the bot.")
while True:
term = input("\nEnter a term to look up: ")
if term.lower() == 'exit':
print("Goodbye!hope to see u next tym")
break
definition, example = get_definition(term)
if definition:
print(f"\nDefinition of '{term}':\n{definition}")
print(f"\nExample:\n{example}")
else:
print(f"No definition found for '{term}'.")
if __name__ == "__main__":
main()
# In[ ]: