|
| 1 | +import argparse, os, json |
| 2 | +from datacite import DataCiteMDSClient,schema40 |
| 3 | +from caltechdata_api import caltechdata_write |
| 4 | + |
| 5 | +parser = argparse.ArgumentParser(description=\ |
| 6 | + "Write files and a DataCite 4 standard json record\ |
| 7 | + to CaltechDATA repository") |
| 8 | +parser.add_argument('json_file', nargs=1, help=\ |
| 9 | + 'file name for json DataCite metadata file') |
| 10 | +parser.add_argument('-ids', nargs='*', help='CaltechDATA IDs') |
| 11 | +parser.add_argument('-fnames', nargs='*', help='New Files') |
| 12 | +args = parser.parse_args() |
| 13 | + |
| 14 | +#Get access token from TIND sed as environment variable with source token.bash |
| 15 | +token = os.environ['TINDTOK'] |
| 16 | + |
| 17 | +metaf = open(args.json_file[0], 'r') |
| 18 | +metadata = json.load(metaf) |
| 19 | + |
| 20 | +production = True |
| 21 | + |
| 22 | +response = caltechdata_write(metadata, token, args.fnames, production) |
| 23 | +print(response) |
| 24 | + |
| 25 | +#If needed - write out datacite XML |
| 26 | + |
| 27 | +xml = schema40.tostring(metadata) |
| 28 | + |
| 29 | +outname = 'datacite.xml' |
| 30 | +outfile = open(outname,'w',encoding='utf8') |
| 31 | +outfile.write(xml) |
| 32 | + |
0 commit comments