-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathattention_grabber.py
46 lines (39 loc) · 1.22 KB
/
attention_grabber.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
import requests
import pandas as pd
import attention_list as api_targets
def add_mentions(my_json):
global mentions
for data in my_json:
try:
doi = data['attributes']['identifiers']['dois']
except KeyError:
doi = None
try:
msm = data['attributes']['mentions']['msm']
except KeyError:
msm = None
try:
policy = data['attributes']['mentions']['policy']
except KeyError:
policy = None
new_df = {'doi': doi, 'msm': msm, 'policy': policy}
mentions.append(new_df)
mentions = []
targets = api_targets.LINK_LIST
for target in targets:
response = requests.get(target)
response_data = response.json()
add_mentions(response_data['data'])
try:
next_link = response_data['links']['next']
except KeyError:
next_link = None
while next_link is not None:
response = requests.get(next_link)
response_data = response.json()
add_mentions(response_data['data'])
try:
next_link = response_data['links']['next']
except KeyError:
next_link = None
pd.DataFrame.from_records(mentions).to_csv('./mentions/mentions.csv')