.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
crossref.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""CrossRef"""
3
4from urllib.parse import urlencode
5from datetime import datetime
6
7about = {
8 "website": "https://www.crossref.org/",
9 "wikidata_id": "Q5188229",
10 "official_api_documentation": "https://api.crossref.org",
11 "use_official_api": False,
12 "require_api_key": False,
13 "results": "JSON",
14}
15
16categories = ["science", "scientific publications"]
17paging = True
18search_url = "https://api.crossref.org/works"
19
20
21def request(query, params):
22 params["url"] = search_url + "?" + urlencode({"query": query, "offset": 20 * (params["pageno"] - 1)})
23 return params
24
25
26def response(resp):
27 results = []
28 for record in resp.json()["message"]["items"]:
29
30 if record["type"] == "component":
31 # These seem to be files published along with papers. Not something you'd search for
32 continue
33 result = {
34 "template": "paper.html",
35 "content": record.get("abstract", ""),
36 "doi": record.get("DOI"),
37 "pages": record.get("page"),
38 "publisher": record.get("publisher"),
39 "tags": record.get("subject"),
40 "type": record.get("type"),
41 "url": record.get("URL"),
42 "volume": record.get("volume"),
43 }
44 if record["type"] == "book-chapter":
45 result["title"] = record["container-title"][0]
46 if record["title"][0].lower().strip() != result["title"].lower().strip():
47 result["title"] += f" ({record['title'][0]})"
48 else:
49 result["title"] = record["title"][0] if "title" in record else record.get("container-title", [None])[0]
50 result["journal"] = record.get("container-title", [None])[0] if "title" in record else None
51
52 if "resource" in record and "primary" in record["resource"] and "URL" in record["resource"]["primary"]:
53 result["url"] = record["resource"]["primary"]["URL"]
54 if "published" in record and "date-parts" in record["published"]:
55 result["publishedDate"] = datetime(*(record["published"]["date-parts"][0] + [1, 1][:3]))
56 result["authors"] = [a.get("given", "") + " " + a.get("family", "") for a in record.get("author", [])]
57 result["isbn"] = record.get("isbn") or [i["value"] for i in record.get("isbn-type", [])]
58 # All the links are not PDFs, even if the URL ends with ".pdf"
59 # result["pdf_url"] = record.get("link", [{"URL": None}])[0]["URL"]
60
61 results.append(result)
62
63 return results
request(query, params)
Definition crossref.py:21