Skip to content

Commit dd5c454

Browse files
committed
Add xml output option and file editing example
1 parent f368996 commit dd5c454

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

caltechdata_api/get_metadata.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def get_metadata(idv,production=True):
3636
and returns DataCite-compatable metadata")
3737
parser.add_argument('ids', metavar='ID', type=int, nargs='+',\
3838
help='The CaltechDATA ID for each record of interest')
39-
parser.add_argument('--test',dest='production', action='store_false')
39+
parser.add_argument('-test',dest='production', action='store_false')
40+
parser.add_argument('-xml',dest='save_xml', action='store_true')
4041

4142
args = parser.parse_args()
4243

@@ -48,3 +49,8 @@ def get_metadata(idv,production=True):
4849
outfile = open(str(idv)+'.json','w')
4950
outfile.write(json.dumps(metadata))
5051
outfile.close()
52+
if args.save_xml == True:
53+
xml = schema40.tostring(metadata)
54+
outfile = open(str(idv)+'.xml','w',encoding='utf8')
55+
outfile.write(xml)
56+

edit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@
1616
metaf = open(args.json_file[0], 'r')
1717
metadata = json.load(metaf)
1818

19-
response = caltechdata_edit(token, args.ids, metadata, args.fnames, {}, False)
19+
production = True
20+
21+
response = caltechdata_edit(token, args.ids, metadata, args.fnames, {'pdf'}, production)
2022
print(response)

edit_files.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import argparse, os, json
2+
from caltechdata_api import caltechdata_edit
3+
4+
parser = argparse.ArgumentParser(description=\
5+
"Write files and a DataCite 4 standard json record\
6+
to CaltechDATA repository")
7+
parser.add_argument('-ids', nargs='*', help='CaltechDATA IDs')
8+
parser.add_argument('-fnames', nargs='*', help='New Files')
9+
parser.add_argument('-delete', nargs='*', help='Files To Delete')
10+
args = parser.parse_args()
11+
12+
#Get access token from TIND sed as environment variable with source token.bash
13+
token = os.environ['TINDTOK']
14+
15+
production = False
16+
17+
response = caltechdata_edit(token, args.ids, {}, args.fnames, args.delete, production)
18+
print(response)

0 commit comments

Comments
 (0)