-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate_api_statics.py
51 lines (41 loc) · 1.59 KB
/
update_api_statics.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
# issue ticket has been opened on this py file
# running this function will update the pickled static response objects
# we use these for shortcuts like mimicking unpaywall response on invalid DOIs and mocks
# wacht the path
from static import PATH_START, PATH_START_PERSONAL
from static import PATH_START_SERVER , PATH_START_PERSONAL_SERVER
import requests
import pickle # will cPickle under the hood
from static import PATH_STATIC_RESPONSES
from static import PATH_STATIC_RESPONSES_ALTMETRIC
do_altmetric = True
if do_altmetric:
# altmetric
#api_ver = 'v1' # may change in future, so here it is. For api-key re-edit with altmetric package
#api_url = "http://api.altmetric.com/%s/" % api_ver
url = 'https://api.altmetric.com/v1/doi/10.1038/480426ax'
r = requests.get(url, params={}, headers={})
r.connection.close()
file_name = PATH_STATIC_RESPONSES_ALTMETRIC
else:
# unpaywall
r = requests.get("https://api.unpaywall.org/[email protected]") # get response on invalid request
r.connection.close() # this removes the link to the connection pool in order to allow pickling
file_name = PATH_STATIC_RESPONSES
print('-----')
print(r.json())
msg = 'check if response above is what you want, enter a y character to continue overwriting else press any other character'
txt = input(msg)
if txt == 'y':
out_file = open(file_name, 'wb')
pickle.dump(r, out_file)
out_file.close()
print('updated file')
else:
print('not saving anything')
print('done')
#in_file = open(file_name, 'rb')
#data = pickle.load(in_file)
#in_file.close()
#print(data)
#print(data.json())