Last active
December 31, 2021 16:59
-
-
Save Itz-fork/a9ca2bf07c3cf3d9fa6ca49b637cc686 to your computer and use it in GitHub Desktop.
Urban Dictionary API example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def search_ud(q): | |
req = requests.get(f"https://nexa-apis.herokuapp.com/ud?query={q}").json() | |
if req["status"] == "Ok": | |
return req["data"] | |
else: | |
return None | |
def_txt = """ | |
Definition: {} | |
Example: {} | |
Sounds (Urls): {} | |
Author: {} | |
Link to Urban Dictionary: {} | |
👍 {} : 👎 {} | |
--------------------------- | |
""" | |
ud = search_ud("Bruh_0x") | |
if ud: | |
for item in ud: | |
defi = item["definition"] | |
ex = item["example"] | |
sounds = item["sounds"] if item["sounds"] else "" | |
auth = item["author"] | |
link = item["link"] | |
likes = item["likes"] | |
dislikes = item["dislikes"] | |
print(def_txt.format(defi, ex, sounds, auth, link, likes, dislikes)) | |
else: | |
print("Oops, Error Happend!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment