-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdoiHandler.py
82 lines (71 loc) · 2.3 KB
/
doiHandler.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import crossref_commons.retrieval
class doiHandler(object):
def __init__(self, doi):
self.doi = doi
def callCrossRef(self):
self.ref = crossref_commons.retrieval.get_publication_as_json(self.doi)
def getMetadata(self):
if not hasattr(self, 'ref'):
self.callCrossRef()
self.articleMetadata = {
'title': self.getTitle(),
'doi': self.doi,
'url': self.getURL(),
'date_published': self.getDatePublished(),
'date_updated': self.getDateUpdated(),
'authors': self.getAuthors(),
'abstract': self.getAbstract()
}
return self.articleMetadata
def getURL(self):
return f"https://doi.org/{self.doi}"
def getAbstract(self):
try:
return self.ref['abstract']
except KeyError:
return None
def getTitle(self):
try:
return self.ref['title']
except KeyError:
return None
def getDatePublished(self):
try:
return self.ref['date-time']
except KeyError:
return None
def getDateUpdated(self):
try:
return self.ref['issued']['date-time']
except KeyError:
return None
def getAuthors(self):
try:
return self.ref['author']
except KeyError:
return None
def getPublisher(self):
try:
return self.ref['publisher']
except KeyError:
return None
# def main():
# rss_url = 'https://opg.optica.org/rss/ao_feed.xml' # Replace with the actual RSS feed URL
# import requests
# entries = fetch_rss_entries(rss_url)
# # print(entries[0]['dc_identifier'])
# abstracts = 0
# doi = entries[0]['dc_identifier'].replace('doi:', '')
# for entry in entries:
# doi = entry['dc_identifier'].replace('doi:', '')
# abstract = getAbstract(doi)
# if abstract:
# abstracts += 1
# else:
# ref = crossref_commons.retrieval.get_publication_as_json(doi)
# print(ref)
# print(f"Total number of entries: {len(entries)}")
# print(f"Total number of abstracts: {abstracts}")
# # doi = "10.1186/1758-2946-4-12" # example
# if __name__ == "__main__":
# main()