67 ret_val: str = CACHE.get(
"X-S2-UI-Version")
71 raise RuntimeError(
"Can't determine Semantic Scholar UI version")
73 doc = html.fromstring(resp.text)
74 ret_val = eval_xpath_getindex(doc,
"//meta[@name='s2-ui-version']/@content", 0)
76 raise RuntimeError(
"Can't determine Semantic Scholar UI version")
78 CACHE.set(
"X-S2-UI-Version", value=ret_val, expire=300)
79 logger.debug(
"X-S2-UI-Version: %s", ret_val)
106def response(resp:
"SXNG_Response") -> EngineResults:
108 json_data = resp.json()
110 for result
in json_data[
"results"]:
111 url: str = result.get(
"primaryPaperLink", {}).get(
"url")
112 if not url
and result.get(
"links"):
113 url = result.get(
"links")[0]
115 alternatePaperLinks = result.get(
"alternatePaperLinks")
116 if alternatePaperLinks:
117 url = alternatePaperLinks[0].get(
"url")
119 url = base_url +
"/paper/%s" % result[
"id"]
121 publishedDate: datetime |
None
122 if "pubDate" in result:
123 publishedDate = datetime.strptime(result[
"pubDate"],
"%Y-%m-%d")
128 authors: list[str] = [author[0][
"name"]
for author
in result.get(
"authors", [])]
132 for doc
in result.get(
"alternatePaperLinks", []):
133 if doc[
"linkType"]
not in (
"crawler",
"doi"):
139 if "citationStats" in result:
141 "{numCitations} citations from the year {firstCitationVelocityYear} to {lastCitationVelocityYear}"
143 numCitations=result[
"citationStats"][
"numCitations"],
144 firstCitationVelocityYear=result[
"citationStats"][
"firstCitationVelocityYear"],
145 lastCitationVelocityYear=result[
"citationStats"][
"lastCitationVelocityYear"],
150 title=result[
"title"][
"text"],
152 content=html_to_text(result[
"paperAbstract"][
"text"]),
153 journal=result.get(
"venue", {}).get(
"text")
or result.get(
"journal", {}).get(
"name"),
154 doi=result.get(
"doiInfo", {}).get(
"doi"),
155 tags=result.get(
"fieldsOfStudy"),
158 publishedDate=publishedDate,