Bladeren bron

:D

master
Jack Moore 4 jaren geleden
bovenliggende
commit
4b84a39654
2 gewijzigde bestanden met toevoegingen van 57 en 1 verwijderingen
  1. +3
    -1
      README.md
  2. +54
    -0
      sauce

+ 3
- 1
README.md Bestand weergeven

@@ -1 +1,3 @@
# gib-sauce
# 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.

+ 54
- 0
sauce Bestand weergeven

@@ -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)

Laden…
Annuleren
Opslaan