tenor.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. import json
  3. import requests
  4. import tempfile
  5. import os
  6. key = "LIVDSRZULELA"
  7. image_viewer = "palemoon"
  8. query = ""
  9. try:
  10. query = sys.argv[1:]
  11. query = ' '.join(query)
  12. except:
  13. while not query:
  14. query = input("Searching for: ")
  15. query = str(query)
  16. size = str(10)
  17. search = f"https://g.tenor.com/v1/search?q={query}&key={key}&limit={size}"
  18. data = requests.get(search)
  19. json_stuff = json.loads(data.text)
  20. if json_stuff["next"] == "0":
  21. print("Nothing found :(")
  22. else:
  23. for i, x in enumerate(json_stuff["results"]):
  24. print(i, x["media"][0]["mediumgif"]["url"])
  25. temp_dir = tempfile.TemporaryDirectory().name
  26. thumbnail_data = requests.get(x["media"][0]["mediumgif"]["url"])
  27. with open(temp_dir, 'wb') as f:
  28. f.write(thumbnail_data.content)
  29. os.system(f"{image_viewer} {temp_dir}")
  30. #c = 100000
  31. #while not c >= 0 or not c <= 29:
  32. # c = input('Number from 1-' + size + " of the URL you want to open: ")
  33. # try:
  34. # c = int(c)
  35. # except:
  36. # c = 100000
  37. #
  38. #selected_url = json_stuff["results"][c]["media"][0]["mediumgif"]["url"]
  39. #
  40. #print(selected_url)