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"
file = "images/test01.jpg"
bovw = False # 是否使用特征检索
bypass = False # 是否绕过 DNS 污染
verify_ssl = True # 是否校验 SSL 证书
@logger.catch()
async def test_async() -> None:
async with Network(proxies=proxies, bypass=bypass, verify_ssl=verify_ssl) as client:
ascii2d = Ascii2D(client=client, bovw=bovw)
# resp = await ascii2d.search(url=url)
resp = await ascii2d.search(file=file)
show_result(resp)
def show_result(resp: Ascii2DResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.url) # 搜索结果链接
selected = next((i for i in resp.raw if i.title or i.url_list), resp.raw[0])
logger.info(selected.origin)
logger.info(selected.thumbnail)
logger.info(selected.title)
logger.info(selected.author)
logger.info(selected.author_url)
logger.info(selected.url)
logger.info(selected.url_list)
logger.info(selected.hash)
logger.info(selected.detail)
logger.info("-" * 50)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(test_async())
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"
file = "images/test01.jpg"
bovw = False # 是否使用特征检索
bypass = False # 是否绕过 DNS 污染
verify_ssl = True # 是否校验 SSL 证书
@logger.catch()
def test_sync() -> None:
ascii2d = Ascii2DSync(
proxies=proxies, bypass=bypass, verify_ssl=verify_ssl, bovw=bovw
)
resp = ascii2d.search(url=url)
# resp = ascii2d.search(file=file)
show_result(resp) # type: ignore
def show_result(resp: Ascii2DResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.url) # 搜索结果链接
selected = next((i for i in resp.raw if i.title or i.url_list), resp.raw[0])
logger.info(selected.origin)
logger.info(selected.thumbnail)
logger.info(selected.title)
logger.info(selected.author)
logger.info(selected.author_url)
logger.info(selected.url)
logger.info(selected.url_list)
logger.info(selected.hash)
logger.info(selected.detail)
logger.info("-" * 50)
if __name__ == "__main__":
test_sync()
// Make sure to add code blocks to your code group
- name: 前往查看
desc: 🚀 测试文件 Demo
link: https://github.com/kitUIN/PicImageSearch/blob/main/demo/cn/demo_ascii2d.py
bgColor: '#DFEEE7'
textColor: '#2A3344'
注意
不建议直接使用 res.raw[0]
,因为其内容可能是空的
建议像示例中那样做判断
程序输出
2022-10-06 01:10:44.551 | INFO | __main__:show_result:39 - https://ascii2d.net/search/color/972f678f86e99ae12c79cd1ea3ece3c3
2022-10-06 01:10:44.551 | INFO | __main__:show_result:43 - <div class="row item-box">
<div class="col-xs-12 col-sm-12 col-md-4 col-xl-4 text-xs-center image-box">
<img loading="lazy" src="/thumbnail/6/e/0/d/6e0d18b51c232dc81b29f0c092c246e5.jpg" alt="6e0d18b51c232dc81b29f0c092c246e5" width="158" height="200"/>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-xl-8 info-box">
<div class="hash">6e0d18b51c232dc81b29f0c092c246e5</div>
<small class="text-muted">2504x3180 JPEG 403.1KB</small>
<div class="pull-xs-right"/>
<div class="detail-box gray-link">
<h6>
<img src="/assets/twitter-15e2a6aec006e029bcccaf870ab8606a4c03a7ff3df90239ff5cd889ca585a39.ico" alt="Twitter" width="14" height="14"/>
<a target="_blank" rel="noopener" href="https://twitter.com/psb694954/status/1455439388393963521">2021.11.02</a>
<a target="_blank" rel="noopener" href="https://twitter.com/intent/user?user_id=2940733338">psb694954</a>
<small class="text-muted">twitter</small>
</h6>
<h6>
<img src="/assets/twitter-15e2a6aec006e029bcccaf870ab8606a4c03a7ff3df90239ff5cd889ca585a39.ico" alt="Twitter" width="14" height="14"/>
<a target="_blank" rel="noopener" href="https://twitter.com/psb694954/status/1472102602792120325">2021.12.18</a>
<a target="_blank" rel="noopener" href="https://twitter.com/intent/user?user_id=2940733338">psb694954</a>
<small class="text-muted">twitter</small>
</h6>
</div>
</div>
<div class="detail-link pull-xs-right hidden-sm-down gray-link">
<span><a href="/search/color/6e0d18b51c232dc81b29f0c092c246e5">色合検索</a></span>
<span><a href="/search/bovw/6e0d18b51c232dc81b29f0c092c246e5">特徴検索</a></span>
<span><a href="/details/6e0d18b51c232dc81b29f0c092c246e5/new">詳細登録</a></span>
</div>
<div class="btn-block text-xs-center hidden-md-up p-d-1">
<a class="btn btn-secondary" href="/search/color/6e0d18b51c232dc81b29f0c092c246e5">色合検索</a>
<a class="btn btn-secondary" href="/search/bovw/6e0d18b51c232dc81b29f0c092c246e5">特徴検索</a>
<a class="btn btn-secondary" href="/details/6e0d18b51c232dc81b29f0c092c246e5/new">詳細登録</a>
</div>
</div>
2022-10-06 01:10:44.551 | INFO | __main__:show_result:44 - https://ascii2d.net/thumbnail/6/e/0/d/6e0d18b51c232dc81b29f0c092c246e5.jpg
2022-10-06 01:10:44.551 | INFO | __main__:show_result:45 - 2021.11.02
2022-10-06 01:10:44.552 | INFO | __main__:show_result:46 - psb694954
2022-10-06 01:10:44.552 | INFO | __main__:show_result:47 - https://twitter.com/intent/user?user_id=2940733338
2022-10-06 01:10:44.552 | INFO | __main__:show_result:48 - https://twitter.com/psb694954/status/1455439388393963521
2022-10-06 01:10:44.552 | INFO | __main__:show_result:49 - [('https://twitter.com/psb694954/status/1455439388393963521', '2021.11.02'), ('https://twitter.com/intent/user?user_id=2940733338', 'psb694954'), ('https://twitter.com/psb694954/status/1472102602792120325', '2021.12.18'), ('https://twitter.com/intent/user?user_id=2940733338', 'psb694954')]
2022-10-06 01:10:44.552 | INFO | __main__:show_result:50 - 6e0d18b51c232dc81b29f0c092c246e5
2022-10-06 01:10:44.552 | INFO | __main__:show_result:51 - 2504x3180 JPEG 403.1KB
Редактировать эту страницу на GitHub (opens new window)
上次更新: 2024/06/30, 23:31:36