File tree 1 file changed +12
-11
lines changed
1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change 1
- from itertools import islice
1
+ import asyncio
2
2
3
3
try :
4
- from duckduckgo_search import DDGS
4
+ from duckduckgo_search import AsyncDDGS
5
5
except ImportError :
6
6
raise ImportError (
7
7
"duckduckgo_search is required to image search. Please install it with `pip install --upgrade duckduckgo_search`."
8
8
)
9
9
10
10
11
11
async def imageSearch (keywords = "cute cats" ):
12
- with DDGS () as ddgs :
13
- return [x for x in islice (ddgs .images (keywords ,safesearch = 'off' ), 50 )]
12
+ async with AsyncDDGS () as ddgs :
13
+ return [
14
+ x async for x in ddgs .images (keywords , safesearch = "off" , max_results = 50 )
15
+ ]
14
16
15
17
16
- if __name__ == "__main__" :
18
+ async def main ():
19
+ result = await imageSearch ()
20
+ print ("result: " , result )
21
+ # result = await imageSearch2()
22
+ # print(result)
17
23
18
- async def main ():
19
- result = await imageSearch ()
20
- print ("result: " ,result )
21
- # result = await imageSearch2()
22
- # print(result)
23
- import asyncio
24
24
25
+ if __name__ == "__main__" :
25
26
asyncio .run (main ())
You can’t perform that action at this time.
0 commit comments