92def response(resp:
"SXNG_Response") -> EngineResults:
97 efetch_xml = etree.XML(resp.content)
100 def _field_txt(xml: ElementType, xpath_str: str) -> str:
101 elem = eval_xpath_getindex(xml, xpath_str, 0, default=
"")
102 return extract_text(elem, allow_none=
True)
or ""
104 for pubmed_article
in eval_xpath_list(efetch_xml,
"//PubmedArticle"):
106 medline_citation: ElementType = eval_xpath_getindex(pubmed_article,
"./MedlineCitation", 0)
107 pubmed_data: ElementType = eval_xpath_getindex(pubmed_article,
"./PubmedData", 0)
109 title: str = eval_xpath_getindex(medline_citation,
".//Article/ArticleTitle", 0).text
110 pmid: str = eval_xpath_getindex(medline_citation,
".//PMID", 0).text
111 url: str = pubmed_url + pmid
112 content = _field_txt(medline_citation,
".//Abstract/AbstractText//text()")
113 doi = _field_txt(medline_citation,
".//ELocationID[@EIdType='doi']/text()")
114 journal = _field_txt(medline_citation,
"./Article/Journal/Title/text()")
115 issn = _field_txt(medline_citation,
"./Article/Journal/ISSN/text()")
117 authors: list[str] = []
119 for author
in eval_xpath_list(medline_citation,
"./Article/AuthorList/Author"):
120 f = eval_xpath_getindex(author,
"./ForeName", 0, default=
None)
121 l = eval_xpath_getindex(author,
"./LastName", 0, default=
None)
122 author_name = f
"{f.text if f is not None else ''} {l.text if l is not None else ''}".strip()
124 authors.append(author_name)
126 accepted_date = eval_xpath_getindex(
127 pubmed_data,
"./History//PubMedPubDate[@PubStatus='accepted']", 0, default=
None
130 if accepted_date
is not None:
131 year = eval_xpath_getindex(accepted_date,
"./Year", 0)
132 month = eval_xpath_getindex(accepted_date,
"./Month", 0)
133 day = eval_xpath_getindex(accepted_date,
"./Day", 0)
135 pub_date = datetime(year=int(year.text), month=int(month.text), day=int(day.text))
148 publishedDate=pub_date,