forked from MolSSI-BSE/basis_set_exchange-xmlconvert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_reference.py
executable file
·52 lines (38 loc) · 1.1 KB
/
add_reference.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
import json
import os
import sys
import glob
import time
import requests
import bse
from bse import curate
reffile = sys.argv[1]
search_str = sys.argv[2]
refs = bse.read_references(reffile)
if search_str.lower().startswith("doi"):
refinfo = curate.query_crossref_doi(search_str[4:])
else:
refinfo = curate.query_crossref(search_str)
if not refinfo:
raise RuntimeError("Crossref didn't find useful data (or none at all)")
first_author = refinfo['authors'][0]
last_name = first_author.split()[-1]
key = curate.create_reference_key(refs, last_name, refinfo['year'])
curate.print_citation(key, refinfo)
if 'DOI' in refinfo:
existing = curate.find_ref_by_doi(refs, refinfo['DOI'])
if existing:
print("Found existing key for doi {} : {}".format(refinfo['DOI'], existing))
quit()
refs[key] = refinfo
while True:
ans = input("Proceed? (y/n) -> ")
ans = ans.lower()
if ans == 'y' or ans == 'n':
break
if ans == 'y':
newfile = reffile + '.new'
bse.write_references(newfile, refs)
print("Changes written to ", newfile)
else:
print("No changes made")