chore: cleanup ruff flake8-simplify linter rules (#8286)
Co-authored-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
@@ -44,36 +44,36 @@ class SearchAPI:
|
||||
@staticmethod
|
||||
def _process_response(res: dict, type: str) -> str:
|
||||
"""Process response from SearchAPI."""
|
||||
if "error" in res.keys():
|
||||
if "error" in res:
|
||||
raise ValueError(f"Got error from SearchApi: {res['error']}")
|
||||
|
||||
toret = ""
|
||||
if type == "text":
|
||||
if "answer_box" in res.keys() and "answer" in res["answer_box"].keys():
|
||||
if "answer_box" in res and "answer" in res["answer_box"]:
|
||||
toret += res["answer_box"]["answer"] + "\n"
|
||||
if "answer_box" in res.keys() and "snippet" in res["answer_box"].keys():
|
||||
if "answer_box" in res and "snippet" in res["answer_box"]:
|
||||
toret += res["answer_box"]["snippet"] + "\n"
|
||||
if "knowledge_graph" in res.keys() and "description" in res["knowledge_graph"].keys():
|
||||
if "knowledge_graph" in res and "description" in res["knowledge_graph"]:
|
||||
toret += res["knowledge_graph"]["description"] + "\n"
|
||||
if "organic_results" in res.keys() and "snippet" in res["organic_results"][0].keys():
|
||||
if "organic_results" in res and "snippet" in res["organic_results"][0]:
|
||||
for item in res["organic_results"]:
|
||||
toret += "content: " + item["snippet"] + "\n" + "link: " + item["link"] + "\n"
|
||||
if toret == "":
|
||||
toret = "No good search result found"
|
||||
|
||||
elif type == "link":
|
||||
if "answer_box" in res.keys() and "organic_result" in res["answer_box"].keys():
|
||||
if "title" in res["answer_box"]["organic_result"].keys():
|
||||
if "answer_box" in res and "organic_result" in res["answer_box"]:
|
||||
if "title" in res["answer_box"]["organic_result"]:
|
||||
toret = f"[{res['answer_box']['organic_result']['title']}]({res['answer_box']['organic_result']['link']})\n"
|
||||
elif "organic_results" in res.keys() and "link" in res["organic_results"][0].keys():
|
||||
elif "organic_results" in res and "link" in res["organic_results"][0]:
|
||||
toret = ""
|
||||
for item in res["organic_results"]:
|
||||
toret += f"[{item['title']}]({item['link']})\n"
|
||||
elif "related_questions" in res.keys() and "link" in res["related_questions"][0].keys():
|
||||
elif "related_questions" in res and "link" in res["related_questions"][0]:
|
||||
toret = ""
|
||||
for item in res["related_questions"]:
|
||||
toret += f"[{item['title']}]({item['link']})\n"
|
||||
elif "related_searches" in res.keys() and "link" in res["related_searches"][0].keys():
|
||||
elif "related_searches" in res and "link" in res["related_searches"][0]:
|
||||
toret = ""
|
||||
for item in res["related_searches"]:
|
||||
toret += f"[{item['title']}]({item['link']})\n"
|
||||
|
||||
@@ -44,12 +44,12 @@ class SearchAPI:
|
||||
@staticmethod
|
||||
def _process_response(res: dict, type: str) -> str:
|
||||
"""Process response from SearchAPI."""
|
||||
if "error" in res.keys():
|
||||
if "error" in res:
|
||||
raise ValueError(f"Got error from SearchApi: {res['error']}")
|
||||
|
||||
toret = ""
|
||||
if type == "text":
|
||||
if "jobs" in res.keys() and "title" in res["jobs"][0].keys():
|
||||
if "jobs" in res and "title" in res["jobs"][0]:
|
||||
for item in res["jobs"]:
|
||||
toret += (
|
||||
"title: "
|
||||
@@ -65,7 +65,7 @@ class SearchAPI:
|
||||
toret = "No good search result found"
|
||||
|
||||
elif type == "link":
|
||||
if "jobs" in res.keys() and "apply_link" in res["jobs"][0].keys():
|
||||
if "jobs" in res and "apply_link" in res["jobs"][0]:
|
||||
for item in res["jobs"]:
|
||||
toret += f"[{item['title']} - {item['company_name']}]({item['apply_link']})\n"
|
||||
else:
|
||||
|
||||
@@ -44,25 +44,25 @@ class SearchAPI:
|
||||
@staticmethod
|
||||
def _process_response(res: dict, type: str) -> str:
|
||||
"""Process response from SearchAPI."""
|
||||
if "error" in res.keys():
|
||||
if "error" in res:
|
||||
raise ValueError(f"Got error from SearchApi: {res['error']}")
|
||||
|
||||
toret = ""
|
||||
if type == "text":
|
||||
if "organic_results" in res.keys() and "snippet" in res["organic_results"][0].keys():
|
||||
if "organic_results" in res and "snippet" in res["organic_results"][0]:
|
||||
for item in res["organic_results"]:
|
||||
toret += "content: " + item["snippet"] + "\n" + "link: " + item["link"] + "\n"
|
||||
if "top_stories" in res.keys() and "title" in res["top_stories"][0].keys():
|
||||
if "top_stories" in res and "title" in res["top_stories"][0]:
|
||||
for item in res["top_stories"]:
|
||||
toret += "title: " + item["title"] + "\n" + "link: " + item["link"] + "\n"
|
||||
if toret == "":
|
||||
toret = "No good search result found"
|
||||
|
||||
elif type == "link":
|
||||
if "organic_results" in res.keys() and "title" in res["organic_results"][0].keys():
|
||||
if "organic_results" in res and "title" in res["organic_results"][0]:
|
||||
for item in res["organic_results"]:
|
||||
toret += f"[{item['title']}]({item['link']})\n"
|
||||
elif "top_stories" in res.keys() and "title" in res["top_stories"][0].keys():
|
||||
elif "top_stories" in res and "title" in res["top_stories"][0]:
|
||||
for item in res["top_stories"]:
|
||||
toret += f"[{item['title']}]({item['link']})\n"
|
||||
else:
|
||||
|
||||
@@ -44,11 +44,11 @@ class SearchAPI:
|
||||
@staticmethod
|
||||
def _process_response(res: dict) -> str:
|
||||
"""Process response from SearchAPI."""
|
||||
if "error" in res.keys():
|
||||
if "error" in res:
|
||||
raise ValueError(f"Got error from SearchApi: {res['error']}")
|
||||
|
||||
toret = ""
|
||||
if "transcripts" in res.keys() and "text" in res["transcripts"][0].keys():
|
||||
if "transcripts" in res and "text" in res["transcripts"][0]:
|
||||
for item in res["transcripts"]:
|
||||
toret += item["text"] + " "
|
||||
if toret == "":
|
||||
|
||||
Reference in New Issue
Block a user