urban-dictionary.py 659 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python
  2. import requests
  3. import json
  4. import sys
  5. bold = "\033[01m"
  6. norm = "\033[00m"
  7. query = ""
  8. try:
  9. query = sys.argv[1:]
  10. except:
  11. while not query:
  12. query = input("Searching for: ")
  13. api = f"https://api.urbandictionary.com/v0/define?term={query}"
  14. data = requests.get(api)
  15. json_stuff = json.loads(data.text)
  16. for i, result in enumerate(json_stuff["list"]):
  17. print(bold+"Word: "+norm+result["word"]+"\n"+bold+"Definition: "+norm+result["definition"].replace("\n","").replace("[","").replace("]","")+"\n" +bold+"Example: "+norm+result["example"].replace("\n","").replace("[","").replace("]","")+"\n---")
  18. if i == 1:
  19. break