Repository navigation
Expand file tree
/
Copy pathbing.py
More file actions
97 lines (79 loc) · 3.42 KB
/
Copy pathbing.py
File metadata and controls
97 lines (79 loc) · 3.42 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import asyncio
from demo.code.config import IMAGE_BASE_URL, PROXIES, get_image_path, logger
from PicImageSearch import Bing, Network
from PicImageSearch.model import BingResponse
from PicImageSearch.sync import Bing as BingSync
url = f"{IMAGE_BASE_URL}/test08.jpg"
file = get_image_path("test08.jpg")
@logger.catch()
async def demo_async() -> None:
async with Network(proxies=PROXIES) as client:
bing = Bing(client=client)
# resp = await bing.search(url=url)
resp = await bing.search(file=file)
show_result(resp)
@logger.catch()
def demo_sync() -> None:
bing = BingSync(proxies=PROXIES)
resp = bing.search(url=url)
# resp = bing.search(file=file)
show_result(resp) # pyright: ignore[reportArgumentType]
def show_result(resp: BingResponse) -> None:
logger.info(f"Search URL: {resp.url}")
for section_name, items in (
("Pages Including", resp.pages_including),
("Visual Search", resp.visual_search),
):
if not items:
continue
logger.info(f"{section_name}:")
for item in items:
logger.info(f" Name: {item.name}")
logger.info(f" URL: {item.url}")
logger.info(f" Thumbnail URL: {item.thumbnail}")
logger.info(f" Image URL: {item.image_url}")
logger.info("-" * 20)
if resp.related_searches:
logger.info("Related Searches:")
for search_item in resp.related_searches:
logger.info(f" Text: {search_item.text}")
logger.info(f" Thumbnail URL: {search_item.thumbnail}")
logger.info("-" * 20)
if travel := resp.travel:
logger.info("Travel:")
logger.info(f" Destination: {travel.destination_name}")
logger.info(f" Travel Guide URL: {travel.travel_guide_url}")
if travel.attractions:
logger.info(" Attractions:")
for attraction in travel.attractions:
logger.info(f" Title: {attraction.title}")
logger.info(f" URL: {attraction.url}")
logger.info(f" Requery URL: {attraction.search_url}")
logger.info(f" Interest Types: {', '.join(attraction.interest_types)}")
logger.info("-" * 20)
if travel.travel_cards:
logger.info(" Travel Cards:")
for card in travel.travel_cards:
logger.info(f" Card Type: {card.card_type}")
logger.info(f" Title: {card.title}")
logger.info(f" Click URL: {card.url}")
logger.info(f" Image URL: {card.image_url}")
logger.info(f" Image Source URL: {card.image_source_url}")
logger.info("-" * 20)
if resp.entities:
logger.info("Entities:")
for entity in resp.entities:
logger.info(f" Name: {entity.name}")
logger.info(f" Thumbnail URL: {entity.thumbnail}")
logger.info(f" Description: {entity.description}")
logger.info(f" Short Description: {entity.short_description}")
if entity.profiles:
logger.info(" Profiles:")
for profile in entity.profiles:
logger.info(f" {profile.get('social_network')}: {profile.get('url')}")
logger.info("-" * 20)
if resp.best_guess:
logger.info(f"Best Guess: {resp.best_guess}")
if __name__ == "__main__":
asyncio.run(demo_async())
# demo_sync()