forked from Shlol762/google-custom-search
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aiohttp): Add async search generator
The async generator (`asearch`) allows iterating through all 100 results which are available from the API. It does this by requesting new pages of results when the results are exhausted.
- Loading branch information
1 parent
002dfbc
commit 78dfc88
Showing
2 changed files
with
65 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
# google-custom-seaerch - search | ||
|
||
from typing import List | ||
|
||
from .types import Item | ||
from .adapter import BaseAdapter | ||
|
||
|
||
class CustomSearch: | ||
"""This is the class used when using Google Custom Search. | ||
Args: | ||
adapter (BaseAdapter): Insert adapter | ||
""" | ||
APIURL: str = "https://www.googleapis.com/customsearch/v1" | ||
|
||
def __init__(self, adapter: BaseAdapter): | ||
self.adapter = adapter | ||
|
||
def search(self, *args, **kwargs) -> List[Item]: | ||
"""This is searched using api. | ||
Args: | ||
query (str): Search keyword | ||
safe (bool): Using safe mode | ||
filter_ (filter): Use filter mode | ||
Returns: | ||
List[Item]: return result | ||
Raises: | ||
ApiNotEnabled: api is not invalid | ||
""" | ||
return self.adapter.search(*args, **kwargs) | ||
# google-custom-seaerch - search | ||
|
||
from typing import List, AsyncGenerator | ||
|
||
from .types import Item | ||
from .adapter import BaseAdapter | ||
|
||
|
||
class CustomSearch: | ||
"""This is the class used when using Google Custom Search. | ||
Args: | ||
adapter (BaseAdapter): Insert adapter | ||
""" | ||
APIURL: str = "https://www.googleapis.com/customsearch/v1" | ||
|
||
def __init__(self, adapter: BaseAdapter): | ||
self.adapter = adapter | ||
|
||
def search(self, *args, **kwargs) -> List[Item]: | ||
"""This is searched using api. | ||
Args: | ||
query (str): Search keyword | ||
safe (bool): Using safe mode | ||
filter_ (filter): Use filter mode | ||
Returns: | ||
List[Item]: return result | ||
Raises: | ||
ApiNotEnabled: api is not invalid | ||
""" | ||
return self.adapter.search(*args, **kwargs) | ||
|
||
async def asearch(self, *args, **kwargs) -> AsyncGenerator[Item, None]: | ||
async for item in self.adapter.asearch(*args, **kwargs): | ||
yield item |