Skip to content

Commit

Permalink
refactor(demo): add logic to get first meaningful result
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoAria committed May 24, 2023
1 parent ea84e2a commit 3ef1012
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions demo/demo_ascii2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def test_sync() -> None:
def show_result(resp: Ascii2DResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.url) # 搜索结果链接
selected = resp.raw[0]
if not (selected.title or selected.url_list):
selected = resp.raw[1]
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)
Expand Down
11 changes: 6 additions & 5 deletions demo/demo_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ def show_result(resp: Optional[GoogleResponse]) -> None:
logger.info(resp.pages)
logger.info(len(resp.pages))
logger.info(resp.url)
# Should start from index 2, because from there is matching image
# logger.info(resp.raw[2].origin)
logger.info(resp.page_number)
logger.info(resp.raw[2].thumbnail)
logger.info(resp.raw[2].title)
logger.info(resp.raw[2].url)
# try to get first result with thumbnail
selected = next((i for i in resp.raw if i.thumbnail), resp.raw[0])
logger.info(selected.origin)
logger.info(selected.thumbnail)
logger.info(selected.title)
logger.info(selected.url)
logger.info("-" * 50)


Expand Down

0 comments on commit 3ef1012

Please sign in to comment.