mirror of
https://github.com/jack-something/gib-sauce
synced 2024-11-22 03:54:15 -05:00
55 lines
1.3 KiB
Python
Executable File
55 lines
1.3 KiB
Python
Executable File
#!/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)
|