60 pubmed_retrieve_api_url = (
61 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?' +
'db=pubmed&retmode=xml&id={pmids_string}'
64 pmids_results = etree.XML(resp.content)
65 pmids = pmids_results.xpath(
'//eSearchResult/IdList/Id')
69 pmids_string += item.text +
','
71 retrieve_notice_args = {
'pmids_string': pmids_string}
73 retrieve_url_encoded = pubmed_retrieve_api_url.format(**retrieve_notice_args)
75 search_results_response = get(retrieve_url_encoded).content
76 search_results = etree.XML(search_results_response)
77 for entry
in eval_xpath_list(search_results,
'//PubmedArticle'):
78 medline = eval_xpath_getindex(entry,
'./MedlineCitation', 0)
80 title = eval_xpath_getindex(medline,
'.//Article/ArticleTitle', 0).text
81 pmid = eval_xpath_getindex(medline,
'.//PMID', 0).text
82 url = pubmed_url + pmid
83 content = extract_text(
84 eval_xpath_getindex(medline,
'.//Abstract/AbstractText//text()', 0, default=
None), allow_none=
True
87 eval_xpath_getindex(medline,
'.//ELocationID[@EIdType="doi"]/text()', 0, default=
None), allow_none=
True
89 journal = extract_text(
90 eval_xpath_getindex(medline,
'./Article/Journal/Title/text()', 0, default=
None), allow_none=
True
93 eval_xpath_getindex(medline,
'./Article/Journal/ISSN/text()', 0, default=
None), allow_none=
True
96 for author
in eval_xpath_list(medline,
'./Article/AuthorList/Author'):
97 f = eval_xpath_getindex(author,
'./ForeName', 0, default=
None)
98 l = eval_xpath_getindex(author,
'./LastName', 0, default=
None)
99 f =
'' if f
is None else f.text
100 l =
'' if l
is None else l.text
101 authors.append((f +
' ' + l).strip())
104 'template':
'paper.html',
107 'content': content
or "",
114 accepted_date = eval_xpath_getindex(
115 entry,
'./PubmedData/History//PubMedPubDate[@PubStatus="accepted"]', 0, default=
None
117 if accepted_date
is not None:
118 year = eval_xpath_getindex(accepted_date,
'./Year', 0)
119 month = eval_xpath_getindex(accepted_date,
'./Month', 0)
120 day = eval_xpath_getindex(accepted_date,
'./Day', 0)
122 publishedDate = datetime.strptime(
123 year.text +
'-' + month.text +
'-' + day.text,
126 res_dict[
'publishedDate'] = publishedDate
127 except Exception
as e:
130 results.append(res_dict)