diff --git a/README.md b/README.md index c9a029b..98f2292 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# gib-sauce \ No newline at end of file +# gib-sauce + +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. \ No newline at end of file diff --git a/sauce b/sauce new file mode 100755 index 0000000..b16bce7 --- /dev/null +++ b/sauce @@ -0,0 +1,54 @@ +#!/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"): + + for i in v: + sources.append(i) + #else: + #sources.append(v) + + return title, sources + + + +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) + + print("\nWith the following pictures:") + for j in arr[1]: + print(str(j)) + + +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: + main(args.url) \ No newline at end of file