-
Notifications
You must be signed in to change notification settings - Fork 21
/
citations.py
48 lines (42 loc) · 1.28 KB
/
citations.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
# IMPORTANT: Citations are now disabled
mailto = "&[email protected]"
headers = {
'User-Agent': 'csindexbr.org; [email protected]',
}
def open_citations_cache(area):
global citations_cache
citations_cache = {}
fname = '../cache/citations/' + area + '-citations.csv'
if os.path.exists(fname):
reader = csv.reader(open(fname, 'r'))
for line in reader:
citations_cache[line[0]] = line[1]
def output_citations_cache(area):
if citations_cache:
f = open('../cache/citations/' + area + '-citations.csv','w')
for doi in citations_cache:
f.write(doi)
f.write(',')
f.write(str(citations_cache[doi]))
f.write('\n')
f.close()
def get_citations(doi):
# citations are now disabled
return 0
if doi in citations_cache:
return citations_cache[doi]
doi_full = doi
i = doi_full.find("10.")
if i == -1:
return -1
doi = doi_full[i:]
url = "https://api.crossref.org/works/" + doi
try:
r = requests.get(url, headers=headers)
doi_json = json.loads(r.text)
citations = doi_json["message"]["is-referenced-by-count"]
citations_cache[doi_full] = citations
time.sleep(4)
return citations
except:
return -1