Skip to content

Commit cd3d2ec

Browse files
committed
Add authors to get_metadata and edit example
1 parent 27b842c commit cd3d2ec

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

caltechdata_api/get_metadata.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,38 @@
88

99

1010
def get_metadata(
11-
idv, production=True, validate=True, emails=False, schema="43", token=False
11+
idv,
12+
production=True,
13+
validate=True,
14+
emails=False,
15+
schema="43",
16+
token=False,
17+
authors=False,
1218
):
1319
# Returns just DataCite metadata or DataCite metadata with emails
1420

1521
if production == True:
16-
url = "https://data.caltech.edu/api/records/"
22+
if authors:
23+
url = "https://authors.library.caltech.edu/api/records/"
24+
else:
25+
url = "https://data.caltech.edu/api/records/"
1726
verify = True
1827
else:
19-
url = "https://data.caltechlibrary.dev/api/records/"
28+
if authors:
29+
url = "https://authors.caltechlibrary.dev/api/records/"
30+
else:
31+
url = "https://data.caltechlibrary.dev/api/records/"
2032
verify = True
2133

22-
headers = {
23-
"accept": "application/vnd.datacite.datacite+json",
24-
}
34+
if authors:
35+
headers = {
36+
"accept": "application/json",
37+
}
38+
validate = False
39+
else:
40+
headers = {
41+
"accept": "application/vnd.datacite.datacite+json",
42+
}
2543

2644
if token:
2745
headers["Authorization"] = "Bearer %s" % token
@@ -58,6 +76,7 @@ def get_metadata(
5876
help="The CaltechDATA ID for each record of interest",
5977
)
6078
parser.add_argument("-test", dest="production", action="store_false")
79+
parser.add_argument("-authors", dest="authors", action="store_true")
6180
parser.add_argument("-xml", dest="save_xml", action="store_true")
6281
parser.add_argument(
6382
"-skip_validate",
@@ -71,14 +90,17 @@ def get_metadata(
7190

7291
production = args.production
7392
schema = args.schema
93+
authors = args.authors
7494
skip_validate = args.skip_validate
7595
if skip_validate:
7696
validate = False
7797
else:
7898
validate = True
7999

80100
for idv in args.ids:
81-
metadata = get_metadata(idv, production, validate, schema)
101+
metadata = get_metadata(
102+
idv, production, validate, schema=schema, authors=authors
103+
)
82104
outfile = open(str(idv) + ".json", "w")
83105
outfile.write(json.dumps(metadata, indent=4))
84106
outfile.close()

edit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
parser.add_argument("-fnames", nargs="*", help="New Files")
1616
parser.add_argument("-flinks", nargs="*", help="New File Links")
1717
parser.add_argument("-schema", default="43", help="Metadata Schema")
18+
parser.add_argument("-authors", action="store_true", help="Edit CaltechAUTHORS")
1819
args = parser.parse_args()
1920

2021
# Get access token set as environment variable with source token.bash
@@ -26,7 +27,7 @@
2627
else:
2728
metadata = {}
2829

29-
production = False
30+
production = True
3031
publish = True
3132

3233
response = caltechdata_edit(
@@ -38,5 +39,6 @@
3839
args.schema,
3940
publish,
4041
args.flinks,
42+
authors=args.authors,
4143
)
4244
print(response)

0 commit comments

Comments
 (0)