33from datacite import DataCiteMDSClient , schema40
44from caltechdata_api import decustomize_schema
55
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
88
99 if production == True :
1010 api_url = "https://data.caltech.edu/api/record/"
@@ -20,15 +20,18 @@ def get_metadata(idv,production=True,auth=None):
2020 raise AssertionError ('expected as metadata property in response, got ' + r_data )
2121 metadata = r_data ['metadata' ]
2222
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 ()
3235
3336 return metadata
3437
@@ -38,6 +41,7 @@ def get_metadata(idv,production=True,auth=None):
3841 and returns DataCite-compatable metadata" )
3942 parser .add_argument ('ids' , metavar = 'ID' , type = int , nargs = '+' ,\
4043 help = 'The CaltechDATA ID for each record of interest' )
44+ parser .add_argument ('-emails' ,dest = 'emails' , action = 'store_true' )
4145 parser .add_argument ('-test' ,dest = 'production' , action = 'store_false' )
4246 parser .add_argument ('-xml' ,dest = 'save_xml' , action = 'store_true' )
4347 parser .add_argument ('-auth_user' ,help = 'Username for basic authentication' )
@@ -46,12 +50,13 @@ def get_metadata(idv,production=True,auth=None):
4650 args = parser .parse_args ()
4751
4852 production = args .production
53+ emails = args .emails
4954 auth = None
5055 if args .auth_user != None :
5156 auth = (args .auth_user ,args .auth_pass )
5257
5358 for idv in args .ids :
54- metadata = get_metadata (idv ,production ,auth )
59+ metadata = get_metadata (idv ,emails , production ,auth )
5560 outfile = open (str (idv )+ '.json' ,'w' )
5661 outfile .write (json .dumps (metadata ))
5762 outfile .close ()
0 commit comments