1
0
mirror of https://gist.github.com/6ba37e4d4084e858f917e271550ce5f6.git synced 2024-09-20 00:34:20 +03:00
picsorter/iqdb.py

22 lines
637 B
Python
Raw Permalink Normal View History

2021-04-14 23:23:56 +03:00
import logging
2021-04-15 12:30:26 +03:00
from typing import Optional
2021-04-14 23:23:56 +03:00
import requests
2021-04-15 12:30:26 +03:00
from bs4 import BeautifulSoup
2021-04-14 23:23:56 +03:00
class Iqdb:
2021-04-15 12:30:26 +03:00
@staticmethod
def search(file: str) -> Optional[str]:
2021-04-14 23:23:56 +03:00
logging.info('Searching %s', file)
files = {'file': open(file, 'rb')}
resp = requests.post('https://iqdb.org/', files=files, timeout=10)
doc = BeautifulSoup(resp.text, 'html.parser')
for tag in doc.select(".image a"):
url = tag.get("href")
if "danbooru.donmai.us/posts" in url:
if url.startswith("//"):
url = "https:" + url
return url
return None