Demo
# Demo
# 示例
import asyncio
from loguru import logger
from PicImageSearch import Ascii2D, Network
from PicImageSearch.model import Ascii2DResponse
# 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" # 搜索本地图片
bovw = True # 是否使用特征检索
@logger.catch()
async def test() -> None:
async with Network(proxies=proxies) as client:
ascii2d = Ascii2D(client=client, bovw=bovw)
resp = await ascii2d.search(url)
show_result(resp)
def show_result(resp: Ascii2DResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.raw[1].origin)
logger.info(resp.raw[1].thumbnail)
logger.info(resp.raw[1].title)
logger.info(resp.raw[1].author)
logger.info(resp.raw[1].author_url)
logger.info(resp.raw[1].url)
logger.info(resp.raw[1].detail)
logger.info(resp.raw[1].mark)
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 Ascii2DResponse
from PicImageSearch.sync import Ascii2D as Ascii2DSync
# 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" # 搜索本地图片
bovw = True # 是否使用特征检索
@logger.catch()
def test_sync() -> None:
ascii2d = Ascii2DSync(proxies=proxies, bovw=bovw)
resp = ascii2d.search(url)
show_result(resp)
def show_result(resp: Ascii2DResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.raw[1].origin)
logger.info(resp.raw[1].thumbnail)
logger.info(resp.raw[1].title)
logger.info(resp.raw[1].author)
logger.info(resp.raw[1].author_url)
logger.info(resp.raw[1].url)
logger.info(resp.raw[1].detail)
logger.info(resp.raw[1].mark)
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
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
// Make sure to add code blocks to your code group
- name: 前往查看
desc: 🚀测试文件Demo
link: https://github.com/kitUIN/PicImageSearch/blob/main/demo/demo_ascii2d.py
bgColor: '#DFEEE7'
textColor: '#2A3344'
1
2
3
4
5
2
3
4
5
注意
不建议使用res.raw[0]
,因为其内容可能是空的
建议从res.raw[1]
开始使用
程序输出,部分过长数据已省略
2022-03-27 17:18:34.344 | INFO | __main__:show_result:36 - <div class="row item-box">...
2022-03-27 17:18:34.345 | INFO | __main__:show_result:37 - https://ascii2d.net/thumbnail/6/e/0/d/6e0d18b51c232dc81b29f0c092c246e5.jpg
2022-03-27 17:18:34.345 | INFO | __main__:show_result:38 - 2021.11.02
2022-03-27 17:18:34.345 | INFO | __main__:show_result:39 - psb694954
2022-03-27 17:18:34.345 | INFO | __main__:show_result:40 - https://twitter.com/intent/user?user_id=2940733338
2022-03-27 17:18:34.345 | INFO | __main__:show_result:41 - https://twitter.com/psb694954/status/1455439388393963521
2022-03-27 17:18:34.345 | INFO | __main__:show_result:42 - 2504x3180 JPEG 403.1KB
2022-03-27 17:18:34.346 | INFO | __main__:show_result:43 - twitter
2022-03-27 17:18:34.346 | INFO | __main__:show_result:44 - --------------------------------------------------
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
上次更新: 2022/03/27, 20:47:51