3
3
from datacite import DataCiteMDSClient , schema40
4
4
from caltechdata_api import decustomize_schema
5
5
6
- def get_metadata (idv ,production = True ,auth = None ):
7
- # Returns just DataCite metadata
6
+ def get_metadata (idv ,production = True ,auth = None , emails = False ):
7
+ # Returns just DataCite metadata or DataCite metadata with emails
8
8
9
9
if production == True :
10
10
api_url = "https://data.caltech.edu/api/record/"
@@ -20,15 +20,18 @@ def get_metadata(idv,production=True,auth=None):
20
20
raise AssertionError ('expected as metadata property in response, got ' + r_data )
21
21
metadata = r_data ['metadata' ]
22
22
23
- metadata = decustomize_schema (metadata )
24
- try :
25
- assert schema40 .validate (metadata )
26
- except AssertionError :
27
- v = schema40 .validator .validate (metadata )
28
- errors = sorted (v .iter_errors (instance ), key = lambda e :e .path )
29
- for error in errors :
30
- print (error .message )
31
- exit ()
23
+ if emails == True :
24
+ metadata = decustomize_schema (metadata ,pass_emails = True )
25
+ else :
26
+ metadata = decustomize_schema (metadata )
27
+ try :
28
+ assert schema40 .validate (metadata )
29
+ except AssertionError :
30
+ v = schema40 .validator .validate (metadata )
31
+ errors = sorted (v .iter_errors (instance ), key = lambda e :e .path )
32
+ for error in errors :
33
+ print (error .message )
34
+ exit ()
32
35
33
36
return metadata
34
37
@@ -38,6 +41,7 @@ def get_metadata(idv,production=True,auth=None):
38
41
and returns DataCite-compatable metadata" )
39
42
parser .add_argument ('ids' , metavar = 'ID' , type = int , nargs = '+' ,\
40
43
help = 'The CaltechDATA ID for each record of interest' )
44
+ parser .add_argument ('-emails' ,dest = 'emails' , action = 'store_true' )
41
45
parser .add_argument ('-test' ,dest = 'production' , action = 'store_false' )
42
46
parser .add_argument ('-xml' ,dest = 'save_xml' , action = 'store_true' )
43
47
parser .add_argument ('-auth_user' ,help = 'Username for basic authentication' )
@@ -46,12 +50,13 @@ def get_metadata(idv,production=True,auth=None):
46
50
args = parser .parse_args ()
47
51
48
52
production = args .production
53
+ emails = args .emails
49
54
auth = None
50
55
if args .auth_user != None :
51
56
auth = (args .auth_user ,args .auth_pass )
52
57
53
58
for idv in args .ids :
54
- metadata = get_metadata (idv ,production ,auth )
59
+ metadata = get_metadata (idv ,emails , production ,auth )
55
60
outfile = open (str (idv )+ '.json' ,'w' )
56
61
outfile .write (json .dumps (metadata ))
57
62
outfile .close ()
0 commit comments