A CLI program which allows you to find where a picture is from, it also prints a bunch of URLs (in the terminal) where you can download the original picture.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

55 Zeilen
1.3KB

  1. #!/usr/bin/env python3
  2. import os
  3. import json
  4. import sys
  5. from urllib.request import Request, urlopen
  6. from urllib.request import urlretrieve
  7. import argparse
  8. def get_json(picture_url):
  9. url = "https://saucenao.com/search.php?db=999&output_type=2&testmode=1&numres=16&url=" + picture_url
  10. req = Request(url, headers={"User-Agent": 'Mozilla/5.0'})
  11. data = json.loads(urlopen(req).read().decode())
  12. return data
  13. def parse_json(data):
  14. title = []
  15. sources = []
  16. for d in data["results"]:
  17. if d["data"]:
  18. for k,v in d["data"].items():
  19. if (k == "material"):
  20. title.append(v)
  21. elif (k == "ext_urls"):
  22. for i in v:
  23. sources.append(i)
  24. #else:
  25. #sources.append(v)
  26. return title, sources
  27. def main(picture_url):
  28. data = get_json(picture_url)
  29. arr = parse_json(data)
  30. print("Found the following matches:")
  31. for i in arr[0]:
  32. print( "-" + i)
  33. print("\nWith the following pictures:")
  34. for j in arr[1]:
  35. print(str(j))
  36. parser = argparse.ArgumentParser()
  37. parser.add_argument("--url", help="url of the picture you wish to look up")
  38. args = parser.parse_args()
  39. if (args.url == None):
  40. print("You need to specify an URL.")
  41. exit(-1)
  42. else:
  43. main(args.url)