-
Notifications
You must be signed in to change notification settings - Fork 14
/
create_person.py
61 lines (43 loc) · 1.65 KB
/
create_person.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
from time import time
from app import db
from util import elapsed
from util import safe_commit
import argparse
from models.person import make_person
from models.orcid import clean_orcid
from models.orcid import NoOrcidException
# needs to be imported so the definitions get loaded into the registry
import jobs_defs
"""
Call from command line to add ORCID profiles based on IDs in a local CSV.
"""
def create_person(dirty_orcid, campaign=None, store_in_db=False):
try:
orcid_id = clean_orcid(dirty_orcid)
except NoOrcidException:
print u"\n\nWARNING: no valid orcid_id in {}; skipping\n\n".format(dirty_orcid)
raise
if store_in_db:
print u"storing in db"
my_person = make_person(orcid_id, store_in_db=True)
if campaign:
my_person.campaign = campaign
db.session.add(my_person)
success = safe_commit(db)
if not success:
print u"ERROR! committing {}".format(my_person.orcid_id)
else:
print u"NOT storing in db"
my_person = make_person(orcid_id, store_in_db=False)
print my_person
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run stuff.")
# just for updating lots
parser.add_argument('orcid_id', type=str, help="ORCID ID to build")
parser.add_argument('--campaign', type=str, help="name of campaign")
parser.add_argument('--store', type=bool, help="store in the database?")
parsed = parser.parse_args()
start = time()
create_person(parsed.orcid_id, parsed.campaign, parsed.store)
db.session.remove()
print "finished update in {}sec".format(elapsed(start))