1
0
mirror of https://github.com/jack-something/gib-sauce synced 2024-11-23 20:20:42 -05:00
gib-sauce/sauce

55 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2019-06-26 10:49:51 -04:00
#!/usr/bin/env python3
import os
import json
import sys
from urllib.request import Request, urlopen
from urllib.request import urlretrieve
import argparse
def get_json(picture_url):
url = "https://saucenao.com/search.php?db=999&output_type=2&testmode=1&numres=16&url=" + picture_url
req = Request(url, headers={"User-Agent": 'Mozilla/5.0'})
data = json.loads(urlopen(req).read().decode())
return data
def parse_json(data):
title = []
sources = []
for d in data["results"]:
if d["data"]:
for k,v in d["data"].items():
if (k == "material"):
title.append(v)
elif (k == "ext_urls"):
2019-06-27 05:33:08 -04:00
2019-06-26 10:49:51 -04:00
for i in v:
sources.append(i)
#else:
#sources.append(v)
return title, sources
2019-06-27 05:33:08 -04:00
2019-06-26 10:49:51 -04:00
def main(picture_url):
data = get_json(picture_url)
arr = parse_json(data)
print("Found the following matches:")
for i in arr[0]:
print( "-" + i)
2019-06-27 05:33:08 -04:00
2019-06-26 10:49:51 -04:00
print("\nWith the following pictures:")
2019-06-27 05:33:08 -04:00
for j in arr[1]:
2019-06-26 10:49:51 -04:00
print(str(j))
2019-06-27 05:33:08 -04:00
2019-06-26 10:49:51 -04:00
parser = argparse.ArgumentParser()
parser.add_argument("--url", help="url of the picture you wish to look up")
args = parser.parse_args()
if (args.url == None):
print("You need to specify an URL.")
exit(-1)
else:
2019-06-27 05:33:08 -04:00
main(args.url)