Skip to content

Instantly share code, notes, and snippets.

@Itz-fork
Last active December 31, 2021 16:59
Show Gist options
  • Save Itz-fork/a9ca2bf07c3cf3d9fa6ca49b637cc686 to your computer and use it in GitHub Desktop.
Save Itz-fork/a9ca2bf07c3cf3d9fa6ca49b637cc686 to your computer and use it in GitHub Desktop.
Urban Dictionary API example
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