-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 部分函数名、参数名、变量名规范化 - 修正一些拼写错误 - 用 `isort` 和 `Black` 对代码格式化
- Loading branch information
Showing
40 changed files
with
842 additions
and
659 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from .network import NetWork | ||
from .tracemoe import AsyncTraceMoe | ||
from .saucenao import AsyncSauceNAO | ||
from .ascii2d import AsyncAscii2D | ||
from .iqdb import AsyncIqdb | ||
from .baidu import AsyncBaiDu | ||
from .google import AsyncGoogle | ||
from .iqdb import AsyncIqdb | ||
from .network import NetWork | ||
from .saucenao import AsyncSauceNAO | ||
from .tracemoe import AsyncTraceMoe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
import time | ||
|
||
from .network import HandOver | ||
from PicImageSearch.Utils import BaiDuResponse | ||
|
||
from .network import HandOver | ||
|
||
class AsyncBaiDu(HandOver): | ||
|
||
class AsyncBaiDu(HandOver): | ||
def __init__(self, **requests_kwargs): | ||
super().__init__(**requests_kwargs) | ||
self.url = 'https://graph.baidu.com/upload' | ||
self.url = "https://graph.baidu.com/upload" | ||
self.requests_kwargs = requests_kwargs | ||
self.headers = { | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45' | ||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45" | ||
} | ||
|
||
async def search(self, url: str) -> BaiDuResponse: | ||
params = { | ||
'uptime': int(time.time()) | ||
} | ||
if url[:4] == 'http': # 网络url | ||
m = {'image': url, | ||
'range': '{"page_from": "searchIndex"}', | ||
'from': "pc", | ||
'tn': 'pc', | ||
'image_source': 'PC_UPLOAD_MOVE', | ||
'sdkParams': '{"data":"a4388c3ef696d354e7f05402e1d38daf48bfb4f3d5bd941e2d0c920dc3b387065b7c85440986897b1f56ef6d352e3b94b3ea435ba5e1bb5a86c5feb88e2e9e1179abd5b8699370b6be8e7cfb96e6e605","key_id":"23","sign":"f22953e8"}' | ||
} | ||
params = {"uptime": int(time.time())} | ||
if url[:4] == "http": # 网络url | ||
m = { | ||
"image": url, | ||
"range": '{"page_from": "searchIndex"}', | ||
"from": "pc", | ||
"tn": "pc", | ||
"image_source": "PC_UPLOAD_MOVE", | ||
"sdkParams": '{"data":"a4388c3ef696d354e7f05402e1d38daf48bfb4f3d5bd941e2d0c920dc3b387065b7c85440986897b1f56ef6d352e3b94b3ea435ba5e1bb5a86c5feb88e2e9e1179abd5b8699370b6be8e7cfb96e6e605","key_id":"23","sign":"f22953e8"}', | ||
} | ||
else: # 文件 | ||
m = {'image': ('filename', open(url, 'rb')), | ||
'range': '{"page_from": "searchIndex"}', | ||
'from': "pc", | ||
'tn': 'pc', | ||
'image_source': 'PC_UPLOAD_SEARCH_FILE', | ||
'sdkParams': '{"data":"a4388c3ef696d354e7f05402e1d38daf48bfb4f3d5bd941e2d0c920dc3b387065b7c85440986897b1f56ef6d352e3b94b3ea435ba5e1bb5a86c5feb88e2e9e1179abd5b8699370b6be8e7cfb96e6e605","key_id":"23","sign":"f22953e8"}' | ||
} | ||
res = await self.post(self.url, _headers=self.headers, _params=params, _data=m) # 上传文件 | ||
url = res.json()['data']['url'] | ||
m = { | ||
"image": ("filename", open(url, "rb")), | ||
"range": '{"page_from": "searchIndex"}', | ||
"from": "pc", | ||
"tn": "pc", | ||
"image_source": "PC_UPLOAD_SEARCH_FILE", | ||
"sdkParams": '{"data":"a4388c3ef696d354e7f05402e1d38daf48bfb4f3d5bd941e2d0c920dc3b387065b7c85440986897b1f56ef6d352e3b94b3ea435ba5e1bb5a86c5feb88e2e9e1179abd5b8699370b6be8e7cfb96e6e605","key_id":"23","sign":"f22953e8"}', | ||
} | ||
res = await self.post( | ||
self.url, _headers=self.headers, _params=params, _data=m | ||
) # 上传文件 | ||
url = res.json()["data"]["url"] | ||
resp = await self.get(url, _headers=self.headers) | ||
return BaiDuResponse(resp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.