Selaa lähdekoodia

minor fixes of pubmed engine

Closes #1045
Noémi Ványi 7 vuotta sitten
vanhempi
commit
d20bba6dc7
3 muutettua tiedostoa jossa 8 lisäystä ja 13 poistoa
  1. 7
    10
      searx/engines/pubmed.py
  2. 1
    1
      searx/settings.yml
  3. 0
    2
      searx/url_utils.py

+ 7
- 10
searx/engines/pubmed.py Näytä tiedosto

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/
12
 """
12
 """
13
 
13
 
14
+from flask_babel import gettext
14
 from lxml import etree
15
 from lxml import etree
15
 from datetime import datetime
16
 from datetime import datetime
16
-from searx.url_utils import urlencode, urlopen
17
+from searx.url_utils import urlencode
18
+from searx.poolrequests import get
17
 
19
 
18
 
20
 
19
 categories = ['science']
21
 categories = ['science']
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}'
48
 
50
 
49
-    # handle Python2 vs Python3 management of bytes and strings
50
-    try:
51
-        pmids_results = etree.XML(resp.text.encode('utf-8'))
52
-    except AttributeError:
53
-        pmids_results = etree.XML(resp.text)
54
-
51
+    pmids_results = etree.XML(resp.content)
55
     pmids = pmids_results.xpath('//eSearchResult/IdList/Id')
52
     pmids = pmids_results.xpath('//eSearchResult/IdList/Id')
56
     pmids_string = ''
53
     pmids_string = ''
57
 
54
 
62
 
59
 
63
     retrieve_url_encoded = pubmed_retrieve_api_url.format(**retrieve_notice_args)
60
     retrieve_url_encoded = pubmed_retrieve_api_url.format(**retrieve_notice_args)
64
 
61
 
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')
67
 
64
 
68
     for entry in search_results:
65
     for entry in search_results:
74
         try:
71
         try:
75
             content = entry.xpath('.//Abstract/AbstractText')[0].text
72
             content = entry.xpath('.//Abstract/AbstractText')[0].text
76
         except:
73
         except:
77
-            content = 'No abstract is available for this publication.'
74
+            content = gettext('No abstract is available for this publication.')
78
 
75
 
79
         #  If a doi is available, add it to the snipppet
76
         #  If a doi is available, add it to the snipppet
80
         try:
77
         try:
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)
83
         except:
80
         except:
84
             pass
81
             pass
85
 
82
 

+ 1
- 1
searx/settings.yml Näytä tiedosto

464
     engine : pubmed
464
     engine : pubmed
465
     shortcut : pub
465
     shortcut : pub
466
     categories: science
466
     categories: science
467
-    oa_first : false
467
+    timeout : 3.0
468
 
468
 
469
   - name : qwant
469
   - name : qwant
470
     engine : qwant
470
     engine : qwant

+ 0
- 2
searx/url_utils.py Näytä tiedosto

3
 if version_info[0] == 2:
3
 if version_info[0] == 2:
4
     from urllib import quote, quote_plus, unquote, urlencode
4
     from urllib import quote, quote_plus, unquote, urlencode
5
     from urlparse import parse_qs, parse_qsl, urljoin, urlparse, urlunparse, ParseResult
5
     from urlparse import parse_qs, parse_qsl, urljoin, urlparse, urlunparse, ParseResult
6
-    from urllib2 import urlopen
7
 else:
6
 else:
8
     from urllib.parse import (
7
     from urllib.parse import (
9
         parse_qs,
8
         parse_qs,
17
         urlunparse,
16
         urlunparse,
18
         ParseResult
17
         ParseResult
19
     )
18
     )
20
-    from urllib.request import urlopen
21
 
19
 
22
 
20
 
23
 __export__ = (parse_qs,
21
 __export__ = (parse_qs,