120def response(resp: "SXNG_Response") -> EngineResults:
121
122 res = EngineResults()
123 json_data = resp.json()
124
125 if (
126 resp.status_code == 403
127 and json_data["status"].lower() == "fail"
128 and "premium feature" in json_data["message"].lower()
129 ):
130 return res
131 raise_for_httperror(resp)
132
133 def field(k: str) -> str:
134 return str(record.get(k, ""))
135
136 for record in json_data["records"]:
137 published = datetime.strptime(record["publicationDate"], "%Y-%m-%d")
138 authors: list[str] = [" ".join(author["creator"].split(", ")[::-1]) for author in record["creators"]]
139
140 pdf_url = ""
141 html_url = ""
142 url_list: list[dict[str, str]] = record["url"]
143
144 for item in url_list:
145 if item["platform"] != "web":
146 continue
147 val = item["value"].replace("http://", "https://", 1)
148 if item["format"] == "html":
149 html_url = val
150 elif item["format"] == "pdf":
151 pdf_url = val
152
153 paper = res.types.Paper(
154 url=html_url,
155
156 pdf_url=pdf_url,
157 title=field("title"),
158 content=field("abstract"),
159 comments=field("publicationName"),
160 tags=record.get("keyword", []),
161 publishedDate=published,
162 type=field("contentType"),
163 authors=authors,
164 publisher=field("publisher"),
165 journal=field("publicationName"),
166 volume=field("volume"),
167 pages="-".join([x for x in [field("startingPage"), field("endingPage")] if x]),
168 number=field("number"),
169 doi=field("doi"),
170 issn=[x for x in [field("issn")] if x],
171 isbn=[x for x in [field("isbn")] if x],
172 )
173 res.add(paper)
174
175 return res