summaryrefslogtreecommitdiff
path: root/searx/engines/pubmed.py
diff options
context:
space:
mode:
authorNoémi Ványi <sitbackandwait@gmail.com>2017-11-01 14:20:47 +0100
committerNoémi Ványi <sitbackandwait@gmail.com>2017-11-01 17:02:38 +0100
commitd20bba6dc74ded16556acf2a404d01ec47455ca6 (patch)
tree6ad6a49a926c30971fd13bb5662aa3df149920f2 /searx/engines/pubmed.py
parentdf0d915806b6e4488099130cd1d7fb1775fe475c (diff)
downloadsearxng-d20bba6dc74ded16556acf2a404d01ec47455ca6.tar.gz
searxng-d20bba6dc74ded16556acf2a404d01ec47455ca6.zip
minor fixes of pubmed engine
Closes #1045
Diffstat (limited to 'searx/engines/pubmed.py')
-rw-r--r--searx/engines/pubmed.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/searx/engines/pubmed.py b/searx/engines/pubmed.py
index abb59d2ed..6451f1467 100644
--- a/searx/engines/pubmed.py
+++ b/searx/engines/pubmed.py
@@ -11,9 +11,11 @@
More info on api: https://www.ncbi.nlm.nih.gov/books/NBK25501/
"""
+from flask_babel import gettext
from lxml import etree
from datetime import datetime
-from searx.url_utils import urlencode, urlopen
+from searx.url_utils import urlencode
+from searx.poolrequests import get
categories = ['science']
@@ -46,12 +48,7 @@ def response(resp):
pubmed_retrieve_api_url = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?'\
+ 'db=pubmed&retmode=xml&id={pmids_string}'
- # handle Python2 vs Python3 management of bytes and strings
- try:
- pmids_results = etree.XML(resp.text.encode('utf-8'))
- except AttributeError:
- pmids_results = etree.XML(resp.text)
-
+ pmids_results = etree.XML(resp.content)
pmids = pmids_results.xpath('//eSearchResult/IdList/Id')
pmids_string = ''
@@ -62,7 +59,7 @@ def response(resp):
retrieve_url_encoded = pubmed_retrieve_api_url.format(**retrieve_notice_args)
- search_results_xml = urlopen(retrieve_url_encoded).read()
+ search_results_xml = get(retrieve_url_encoded).content
search_results = etree.XML(search_results_xml).xpath('//PubmedArticleSet/PubmedArticle/MedlineCitation')
for entry in search_results:
@@ -74,12 +71,12 @@ def response(resp):
try:
content = entry.xpath('.//Abstract/AbstractText')[0].text
except:
- content = 'No abstract is available for this publication.'
+ content = gettext('No abstract is available for this publication.')
# If a doi is available, add it to the snipppet
try:
doi = entry.xpath('.//ELocationID[@EIdType="doi"]')[0].text
- content = 'DOI: ' + doi + ' Abstract: ' + content
+ content = 'DOI: {doi} Abstract: {content}'.format(doi=doi, content=content)
except:
pass