Demo
# Demo
# 示例
import asyncio
from loguru import logger
from PicImageSearch import Network, SauceNAO
from PicImageSearch.model import SauceNAOResponse
# proxies = "http://127.0.0.1:1081"
proxies = None
# url = "https://raw.githubusercontent.com/kitUIN/PicImageSearch/main/demo/images/test01.jpg"
url = r"images/test01.jpg" # 搜索本地图片
api_key = "a4ab3f81009b003528f7e31aed187fa32a063f58"
@logger.catch()
async def test() -> None:
async with Network(proxies=proxies) as client:
saucenao = SauceNAO(client=client, api_key=api_key)
resp = await saucenao.search(url)
show_result(resp)
def show_result(resp: SauceNAOResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.raw[0].origin)
logger.info(resp.long_remaining)
logger.info(resp.short_remaining)
logger.info(resp.raw[0].thumbnail)
logger.info(resp.raw[0].similarity)
logger.info(resp.raw[0].title)
logger.info(resp.raw[0].author)
logger.info(resp.raw[0].url)
logger.info(resp.raw[0].pixiv_id)
logger.info(resp.raw[0].member_id)
logger.info("-" * 50)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(test())
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from loguru import logger
from PicImageSearch.model import SauceNAOResponse
from PicImageSearch.sync import SauceNAO as SauceNAOSync
# proxies = "http://127.0.0.1:1081"
proxies = None
# url = "https://raw.githubusercontent.com/kitUIN/PicImageSearch/main/demo/images/test01.jpg"
url = r"images/test01.jpg" # 搜索本地图片
api_key = "a4ab3f81009b003528f7e31aed187fa32a063f58"
@logger.catch()
def test_sync() -> None:
saucenao = SauceNAOSync(proxies=proxies, api_key=api_key)
resp = saucenao.search(url)
show_result(resp)
def show_result(resp: SauceNAOResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.raw[0].origin)
logger.info(resp.long_remaining)
logger.info(resp.short_remaining)
logger.info(resp.raw[0].thumbnail)
logger.info(resp.raw[0].similarity)
logger.info(resp.raw[0].title)
logger.info(resp.raw[0].author)
logger.info(resp.raw[0].url)
logger.info(resp.raw[0].pixiv_id)
logger.info(resp.raw[0].member_id)
logger.info("-" * 50)
if __name__ == "__main__":
test_sync()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Make sure to add code blocks to your code group
- name: 前往查看
desc: 🚀测试文件Demo
link: https://github.com/kitUIN/PicImageSearch/blob/main/demo/demo_saucenao.py
bgColor: '#DFEEE7'
textColor: '#2A3344'
1
2
3
4
5
2
3
4
5
程序输出,部分过长数据已省略
2022-03-27 19:55:13.534 | INFO | __main__:show_result:36 - {'header': {'similarity': '93.38', 'thumbnail': 'https://img1.saucenao.com/res/pixiv/9416/94165837_p0_master1200.jpg?auth=JHjYcfJiOPazYbW-g8DwKw&exp=1648580400', 'index_id': 5, 'index_name': 'Index #5: Pixiv Images - 94165837_p0_master1200.jpg', 'dupes': 0, 'hidden': 0}, 'data': {'ext_urls': ['https://www.pixiv.net/member_illust.php?mode=medium&illust_id=94165837'], 'title': 'いたずら', 'pixiv_id': 94165837, 'member_name': 'SyHan__', 'member_id': 12505972}}
2022-03-27 19:55:13.534 | INFO | __main__:show_result:37 - 193
2022-03-27 19:55:13.534 | INFO | __main__:show_result:38 - 5
2022-03-27 19:55:13.534 | INFO | __main__:show_result:39 - https://img1.saucenao.com/res/pixiv/9416/94165837_p0_master1200.jpg?auth=JHjYcfJiOPazYbW-g8DwKw&exp=1648580400
2022-03-27 19:55:13.534 | INFO | __main__:show_result:40 - 93.38
2022-03-27 19:55:13.534 | INFO | __main__:show_result:41 - いたずら
2022-03-27 19:55:13.534 | INFO | __main__:show_result:42 - SyHan__
2022-03-27 19:55:13.534 | INFO | __main__:show_result:43 - https://www.pixiv.net/member_illust.php?mode=medium&illust_id=94165837
2022-03-27 19:55:13.534 | INFO | __main__:show_result:44 - 94165837
2022-03-27 19:55:13.534 | INFO | __main__:show_result:45 - 12505972
2022-03-27 19:55:13.534 | INFO | __main__:show_result:46 - --------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
上次更新: 2022/03/27, 20:47:51