fix: bocha filter list
Co-Authored-By: zengxy <11961641+zengxy@users.noreply.github.com>
This commit is contained in:
co-authored by
zengxy
parent
823b9a6dd9
commit
b5bd8704fe
@@ -9,13 +9,13 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def _parse_response(response):
|
def _parse_response(response):
|
||||||
result = {}
|
results = []
|
||||||
if "data" in response:
|
if "data" in response:
|
||||||
data = response["data"]
|
data = response["data"]
|
||||||
if "webPages" in data:
|
if "webPages" in data:
|
||||||
webPages = data["webPages"]
|
webPages = data["webPages"]
|
||||||
if "value" in webPages:
|
if "value" in webPages:
|
||||||
result["webpage"] = [
|
results = [
|
||||||
{
|
{
|
||||||
"id": item.get("id", ""),
|
"id": item.get("id", ""),
|
||||||
"name": item.get("name", ""),
|
"name": item.get("name", ""),
|
||||||
@@ -29,7 +29,7 @@ def _parse_response(response):
|
|||||||
}
|
}
|
||||||
for item in webPages["value"]
|
for item in webPages["value"]
|
||||||
]
|
]
|
||||||
return result
|
return results
|
||||||
|
|
||||||
|
|
||||||
def search_bocha(
|
def search_bocha(
|
||||||
@@ -51,7 +51,7 @@ def search_bocha(
|
|||||||
response = requests.post(url, headers=headers, data=payload, timeout=5)
|
response = requests.post(url, headers=headers, data=payload, timeout=5)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
results = _parse_response(response.json())
|
results = _parse_response(response.json())
|
||||||
print(results)
|
|
||||||
if filter_list:
|
if filter_list:
|
||||||
results = get_filtered_results(results, filter_list)
|
results = get_filtered_results(results, filter_list)
|
||||||
|
|
||||||
@@ -59,5 +59,5 @@ def search_bocha(
|
|||||||
SearchResult(
|
SearchResult(
|
||||||
link=result["url"], title=result.get("name"), snippet=result.get("summary")
|
link=result["url"], title=result.get("name"), snippet=result.get("summary")
|
||||||
)
|
)
|
||||||
for result in results.get("webpage", [])[:count]
|
for result in results[:count]
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user