Skip to content

Commit

Permalink
添加saucenao代理模式
Browse files Browse the repository at this point in the history
  • Loading branch information
kitUIN committed Nov 20, 2020
1 parent 8057d77 commit a9369ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion PicImageSearch/saucenao.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(self,
dbmask: int = None,
dbmaski: int = None,
db: int = 999,
**requests_kwargs
) -> None:
"""
:param api_key:(str)用于SauceNAO的访问密钥 (默认=None)
Expand All @@ -128,6 +129,7 @@ def __init__(self,
:param hide:(int)结果隐藏控制,无=0,明确返回值(默认)=1,怀疑返回值=2,全部返回值=3
"""
# minsim 控制最小相似度
self.requests_kwargs = requests_kwargs
params = dict()
if api_key is not None:
params['api_key'] = api_key
Expand Down Expand Up @@ -155,7 +157,7 @@ def search(self, url: str, files=None):
image.save(imageData, format='PNG')
files = {'file': ("image.png", imageData.getvalue())}
imageData.close()
resp = requests.post(self.SauceNAOURL, params=params, files=files)
resp = requests.post(self.SauceNAOURL, params=params, files=files,**self.requests_kwargs)
status_code = resp.status_code
logger.info(status_code)
data = resp.json()
Expand Down
11 changes: 9 additions & 2 deletions test/test2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@

from PicImageSearch.saucenao import SauceNAO

saucenao = SauceNAO(api_key='54a8d90c583d3b66b6dd3d7e9001a39b588cd842',testmode=1)
_REQUESTS_KWARGS = {
'proxies': {
'https': 'http://127.0.0.1:10809',
}
# 如果需要代理
}
saucenao = SauceNAO(api_key='54a8d90c583d3b66b6dd3d7e9001a39b588cd842', testmode=1, **_REQUESTS_KWARGS)
res = saucenao.search('https://cdn.jsdelivr.net/gh/laosepi/setu/pics_original/77702503_p0.jpg')
logger.info(res.origin) # 原始数据
logger.info(res.raw) #
logger.info(res.raw[0]) #
logger.info(res.long_remaining) # 99
logger.info(res.short_remaining) # 3
logger.info(res.raw[0].thumbnail) # https://img1.saucenao.com/res/pixiv/7770/77702503_p0_master1200.jpg?auth=pJmiu8qNI1z2fLBAlAsx7A&exp=1604748473
logger.info(res.raw[
0].thumbnail) # https://img1.saucenao.com/res/pixiv/7770/77702503_p0_master1200.jpg?auth=pJmiu8qNI1z2fLBAlAsx7A&exp=1604748473
logger.info(res.raw[0].similarity) # 92.22
logger.info(res.raw[0].title) # MDR♡
logger.info(res.raw[0].author) # CeNanGam
Expand Down
8 changes: 7 additions & 1 deletion wiki/SauceNAO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
```
from loguru import logger
from PicImageSeach.saucenao import SauceNAO
saucenao = SauceNAO()
_REQUESTS_KWARGS = {
# 'proxies': {
# 'https': 'http://127.0.0.1:10809',
# }
#如果需要代理
}
saucenao = SauceNAO(**_REQUESTS_KWARGS)
res = saucenao.search('https://cdn.jsdelivr.net/gh/laosepi/setu/pics_original/77702503_p0.jpg')
#res = saucenao.search(r'C:/kitUIN/img/tinted-good.jpg')搜索本地图片
logger.info(res.origin) # 原始数据
Expand Down

0 comments on commit a9369ba

Please sign in to comment.