diff --git a/graph/component/arxiv.py b/graph/component/arxiv.py
index ed205998193..7d485a43bde 100644
--- a/graph/component/arxiv.py
+++ b/graph/component/arxiv.py
@@ -47,22 +47,25 @@ def _run(self, history, **kwargs):
if not ans:
return ArXiv.be_output("")
- sort_choices = {"relevance": arxiv.SortCriterion.Relevance,
- "lastUpdatedDate": arxiv.SortCriterion.LastUpdatedDate,
- 'submittedDate': arxiv.SortCriterion.SubmittedDate}
- arxiv_client = arxiv.Client()
- search = arxiv.Search(
- query=ans,
- max_results=self._param.top_n,
- sort_by=sort_choices[self._param.sort_by]
- )
- arxiv_res = [
- {"content": 'Title: ' + i.title + '\nPdf_Url: \nSummary: ' + i.summary} for
- i in list(arxiv_client.results(search))]
+ try:
+ sort_choices = {"relevance": arxiv.SortCriterion.Relevance,
+ "lastUpdatedDate": arxiv.SortCriterion.LastUpdatedDate,
+ 'submittedDate': arxiv.SortCriterion.SubmittedDate}
+ arxiv_client = arxiv.Client()
+ search = arxiv.Search(
+ query=ans,
+ max_results=self._param.top_n,
+ sort_by=sort_choices[self._param.sort_by]
+ )
+ arxiv_res = [
+ {"content": 'Title: ' + i.title + '\nPdf_Url: \nSummary: ' + i.summary} for
+ i in list(arxiv_client.results(search))]
+ except Exception as e:
+ return ArXiv.be_output("**ERROR**: " + str(e))
if not arxiv_res:
return ArXiv.be_output("")
df = pd.DataFrame(arxiv_res)
if DEBUG: print(df, ":::::::::::::::::::::::::::::::::")
- return df
\ No newline at end of file
+ return df
diff --git a/graph/component/baidu.py b/graph/component/baidu.py
index 7616be0bb32..024917cc08f 100644
--- a/graph/component/baidu.py
+++ b/graph/component/baidu.py
@@ -45,16 +45,20 @@ def _run(self, history, **kwargs):
if not ans:
return Baidu.be_output("")
- url = 'https://www.baidu.com/s?wd=' + ans + '&rn=' + str(self._param.top_n)
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'}
- response = requests.get(url=url, headers=headers)
+ try:
+ url = 'https://www.baidu.com/s?wd=' + ans + '&rn=' + str(self._param.top_n)
+ headers = {
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'}
+ response = requests.get(url=url, headers=headers)
- url_res = re.findall(r"'url': \\\"(.*?)\\\"}", response.text)
- title_res = re.findall(r"'title': \\\"(.*?)\\\",\\n", response.text)
- body_res = re.findall(r"\"contentText\":\"(.*?)\"", response.text)
- baidu_res = [{"content": re.sub('|', '', '' + title + ' ' + body)} for url, title, body in zip(url_res, title_res, body_res)]
- del body_res, url_res, title_res
+ url_res = re.findall(r"'url': \\\"(.*?)\\\"}", response.text)
+ title_res = re.findall(r"'title': \\\"(.*?)\\\",\\n", response.text)
+ body_res = re.findall(r"\"contentText\":\"(.*?)\"", response.text)
+ baidu_res = [{"content": re.sub('|', '', '' + title + ' ' + body)} for
+ url, title, body in zip(url_res, title_res, body_res)]
+ del body_res, url_res, title_res
+ except Exception as e:
+ return Baidu.be_output("**ERROR**: " + str(e))
if not baidu_res:
return Baidu.be_output("")
diff --git a/graph/component/duckduckgo.py b/graph/component/duckduckgo.py
index 085ea416e86..e796b4af6d2 100644
--- a/graph/component/duckduckgo.py
+++ b/graph/component/duckduckgo.py
@@ -46,16 +46,19 @@ def _run(self, history, **kwargs):
if not ans:
return DuckDuckGo.be_output("")
- if self._param.channel == "text":
- with DDGS() as ddgs:
- # {'title': '', 'href': '', 'body': ''}
- duck_res = [{"content": '' + i["title"] + ' ' + i["body"]} for i in
- ddgs.text(ans, max_results=self._param.top_n)]
- elif self._param.channel == "news":
- with DDGS() as ddgs:
- # {'date': '', 'title': '', 'body': '', 'url': '', 'image': '', 'source': ''}
- duck_res = [{"content": '' + i["title"] + ' ' + i["body"]} for i in
- ddgs.news(ans, max_results=self._param.top_n)]
+ try:
+ if self._param.channel == "text":
+ with DDGS() as ddgs:
+ # {'title': '', 'href': '', 'body': ''}
+ duck_res = [{"content": '' + i["title"] + ' ' + i["body"]} for i
+ in ddgs.text(ans, max_results=self._param.top_n)]
+ elif self._param.channel == "news":
+ with DDGS() as ddgs:
+ # {'date': '', 'title': '', 'body': '', 'url': '', 'image': '', 'source': ''}
+ duck_res = [{"content": '' + i["title"] + ' ' + i["body"]} for i
+ in ddgs.news(ans, max_results=self._param.top_n)]
+ except Exception as e:
+ return DuckDuckGo.be_output("**ERROR**: " + str(e))
if not duck_res:
return DuckDuckGo.be_output("")
diff --git a/graph/component/pubmed.py b/graph/component/pubmed.py
index 23abd8139da..1c76cf93c87 100644
--- a/graph/component/pubmed.py
+++ b/graph/component/pubmed.py
@@ -46,14 +46,18 @@ def _run(self, history, **kwargs):
if not ans:
return PubMed.be_output("")
- Entrez.email = self._param.email
- pubmedids = Entrez.read(Entrez.esearch(db='pubmed', retmax=self._param.top_n, term=ans))['IdList']
- pubmedcnt = ET.fromstring(
- Entrez.efetch(db='pubmed', id=",".join(pubmedids), retmode="xml").read().decode("utf-8"))
- pubmed_res = [{"content": 'Title:' + child.find("MedlineCitation").find("Article").find(
- "ArticleTitle").text + '\nUrl:' + '\n' + 'Abstract:' + child.find("MedlineCitation").find(
- "Article").find("Abstract").find("AbstractText").text} for child in pubmedcnt.findall("PubmedArticle")]
+ try:
+ Entrez.email = self._param.email
+ pubmedids = Entrez.read(Entrez.esearch(db='pubmed', retmax=self._param.top_n, term=ans))['IdList']
+ pubmedcnt = ET.fromstring(
+ Entrez.efetch(db='pubmed', id=",".join(pubmedids), retmode="xml").read().decode("utf-8"))
+ pubmed_res = [{"content": 'Title:' + child.find("MedlineCitation").find("Article").find(
+ "ArticleTitle").text + '\nUrl:' + '\n' + 'Abstract:' + child.find(
+ "MedlineCitation").find("Article").find("Abstract").find("AbstractText").text} for child in
+ pubmedcnt.findall("PubmedArticle")]
+ except Exception as e:
+ return PubMed.be_output("**ERROR**: " + str(e))
if not pubmed_res:
return PubMed.be_output("")
diff --git a/graph/component/wikipedia.py b/graph/component/wikipedia.py
index df7e313a2ae..6a4b015d7aa 100644
--- a/graph/component/wikipedia.py
+++ b/graph/component/wikipedia.py
@@ -51,16 +51,15 @@ def _run(self, history, **kwargs):
if not ans:
return Wikipedia.be_output("")
- wiki_res = []
- wikipedia.set_lang(self._param.language)
- wiki_engine = wikipedia
- for wiki_key in wiki_engine.search(ans, results=self._param.top_n):
- try:
+ try:
+ wiki_res = []
+ wikipedia.set_lang(self._param.language)
+ wiki_engine = wikipedia
+ for wiki_key in wiki_engine.search(ans, results=self._param.top_n):
page = wiki_engine.page(title=wiki_key, auto_suggest=False)
wiki_res.append({"content": '' + page.title + ' ' + page.summary})
- except Exception as e:
- print(e)
- pass
+ except Exception as e:
+ return Wikipedia.be_output("**ERROR**: " + str(e))
if not wiki_res:
return Wikipedia.be_output("")