Repository navigation
Expand file tree
/
Copy pathcrossref.py
More file actions
36 lines (33 loc) · 1.43 KB
/
Copy pathcrossref.py
File metadata and controls
36 lines (33 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
from dotenv import load_dotenv
import requests
load_dotenv()
CROSSREFAPI = "https://api.crossref.org/works/"
#Should simply call the API and return the corresponding metadata as a JSON for easy use
#Potentially restruct API to recursively look into the other articles each relevant article cites, as they may be relevant.
def get_metadata(DOI):
try:
metadata = requests.get(CROSSREFAPI + DOI)
if (metadata.status_code != 200):
print(f"Crossref failed to find the DOI {DOI}")
return -1
metadata = metadata.json()
return_dict= {}
return_dict["publisher"] = metadata["message"]["publisher"] #This one is kinda needed.
if "abstract" in metadata["message"]:
return_dict["abstract"] = metadata["message"]["abstract"]
if "author" in metadata["message"]:
return_dict["authors"] = [author["given"] for author in metadata["message"]["author"]]
if "reference-count" in metadata["message"]:
return_dict["citation_count"] = metadata["message"]["reference-count"]
return return_dict
except Exception as e:
print(f"Error occured: {e}")
return -1
if __name__ == "__main__":
doi = "10.1186/s12967-024-05098-7"
metadata = get_metadata(doi)
if (metadata == -1):
print(f"Failed to retrieve metadata for {doi}")
else:
print(f"Succesfully retrieved metadata: {metadata}")