-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjournals.py
81 lines (64 loc) · 2.2 KB
/
journals.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
"""
journals.py
An example of building a systematic literature review using the Crossref API's
journals/{issn}/works endpoint.
"""
# Imports
from habanero import Crossref
from utils.constants import *
from utils.functions import convert_to_dataframe
# Constants
EXCEL_FILE = BASE_DIR / 'literature_review.xlsx'
FILTERS = {
'from-pub-date': '2007-01-01'
}
# The ISSN of all journals you need to fetch publications from
ISSN_LIST = [
'0007-1080',
'0019-7939',
'0034-379X',
'0268-1072',
'2053-9517',
'1477-7487'
]
def main():
"""
This is the script's main function, where all the work is done.
"""
print('Hello World! Starting script...')
try:
print('Connecting to Crossref...')
cr = Crossref(mailto=MAILTO, ua_string='literature-review/0.1')
dataset = []
for issn in ISSN_LIST:
print(f"Fetching publications for journal ISSN {issn}...")
response = cr.journals(ids=issn,
works=True,
filter=FILTERS,
select=METADATA,
cursor='*',
progress_bar=True,
warn=True)
batches = [
batch['message']['items']
for batch in response if batch['status'] == 'ok'
]
items = [item for batch in batches for item in batch]
print(f"{len(items)} publications retrieved...")
dataset += items
print('Converting data to dataframe...')
dataframe = convert_to_dataframe(dataset)
print('Saving dataframe to Excel...')
dataframe.to_excel(EXCEL_FILE, index=False)
except Exception as e:
print(f"Could not complete literature review because of {e}")
finally:
print('End of script.')
if __name__ == '__main__':
import sys
if sys.version_info.major < 3 or \
(sys.version_info.major == 3 and sys.version_info.minor < 8):
msg = f"Python 3.8 and over is required to run this script. " + \
f"Current installation: {sys.version}"
raise Exception(msg)
main()