@@ -11,9 +11,11 @@
11 More info on api: https://www.ncbi.nlm.nih.gov/books/NBK25501/
11 More info on api: https://www.ncbi.nlm.nih.gov/books/NBK25501/
14+from flask_babel import gettext
14from lxml import etree
15from lxml import etree
15from datetime import datetime
16from datetime import datetime
16−from searx.url_utils import urlencode, urlopen
17+from searx.url_utils import urlencode
18+from searx.poolrequests import get
19categories = ['science']
21categories = ['science']
@@ -46,12 +48,7 @@ def response(resp):
46 pubmed_retrieve_api_url = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?'\
48 pubmed_retrieve_api_url = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?'\
47 + 'db=pubmed&retmode=xml&id={pmids_string}'
49 + 'db=pubmed&retmode=xml&id={pmids_string}'
49− # handle Python2 vs Python3 management of bytes and strings
51− pmids_results = etree.XML(resp.text.encode('utf-8'))
51+ pmids_results = etree.XML(resp.content)
52− except AttributeError:
53− pmids_results = etree.XML(resp.text)
55 pmids = pmids_results.xpath('//eSearchResult/IdList/Id')
52 pmids = pmids_results.xpath('//eSearchResult/IdList/Id')
56 pmids_string = ''
53 pmids_string = ''
@@ -62,7 +59,7 @@ def response(resp):
63 retrieve_url_encoded = pubmed_retrieve_api_url.format(**retrieve_notice_args)
60 retrieve_url_encoded = pubmed_retrieve_api_url.format(**retrieve_notice_args)
65− search_results_xml = urlopen(retrieve_url_encoded).read()
62+ search_results_xml = get(retrieve_url_encoded).content
66 search_results = etree.XML(search_results_xml).xpath('//PubmedArticleSet/PubmedArticle/MedlineCitation')
63 search_results = etree.XML(search_results_xml).xpath('//PubmedArticleSet/PubmedArticle/MedlineCitation')
68 for entry in search_results:
65 for entry in search_results:
@@ -74,12 +71,12 @@ def response(resp):
75 content = entry.xpath('.//Abstract/AbstractText')[0].text
72 content = entry.xpath('.//Abstract/AbstractText')[0].text
77− content = 'No abstract is available for this publication.'
74+ content = gettext('No abstract is available for this publication.')
79 # If a doi is available, add it to the snipppet
76 # If a doi is available, add it to the snipppet
81 doi = entry.xpath('.//ELocationID[@EIdType="doi"]')[0].text
78 doi = entry.xpath('.//ELocationID[@EIdType="doi"]')[0].text
82− content = 'DOI: ' + doi + ' Abstract: ' + content
79+ content = 'DOI: {doi} Abstract: {content}'.format(doi=doi, content=content)