-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.py
More file actions
123 lines (115 loc) · 4.74 KB
/
template.py
File metadata and controls
123 lines (115 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os, argparse
from caltechdata_api import caltechdata_write
from datetime import datetime
from traceback import format_exc
from utils import format_error
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Create a template record in CaltechAUTHORS"
)
parser.add_argument("harvest_type", help="california_tech")
parser.add_argument("-issue", help="Issue number")
parser.add_argument("-volume", help="Volume number")
parser.add_argument("-date", help="Publication date (YYYY-MM-DD)")
parser.add_argument("-actor", help="Name of actor to use for review message")
parser.add_argument("-test", action="store_true", help="Use the test environment")
args = parser.parse_args()
try:
formatted_date = datetime.strptime(args.date, "%Y-%m-%d").strftime("%B %-d, %Y")
except ValueError:
raise ValueError(f"Invalid date format (expected YYYY-MM-DD): {args.date}")
token = os.getenv("RDMTOK")
harvest_type = args.harvest_type
if args.test:
production = False
else:
production = True
if harvest_type == "california_tech":
if production:
community = "2de36d2e-df7d-4daa-85c2-31334ffec356"
else:
community = "8f398a9c-4c33-48ae-a60e-c5c96438121c"
metadata = {
"custom_fields": {
"caltech:publication_status": [{"id": "published"}],
"imprint:imprint": {"place": "Pasadena, CA"},
"journal:journal": {
"issue": args.issue,
"title": "California Tech",
"volume": args.volume,
},
},
"metadata": {
"additional_titles": [
{
"lang": {"id": "eng"},
"title": "Tech",
"type": {"id": "alternative-title"},
}
],
"contributors": [
{
"person_or_org": {
"family_name": "Wilson",
"given_name": "Damien",
"identifiers": [
{"identifier": "Wilson-Damien", "scheme": "clpid"}
],
"name": "Wilson, Damien",
"type": "personal",
},
"role": {"id": "editor"},
}
],
"creators": [
{
"affiliations": [{"id": "05dxps055"}],
"person_or_org": {
"identifiers": [
{
"identifier": "Associated-Students-of-the-California-Institute-of-Technology",
"scheme": "clpid",
}
],
"name": "Associated Students of the California Institute of Technology, Inc.",
"type": "organizational",
},
"role": {"id": "issuing-body"},
}
],
"languages": [{"id": "eng"}],
"publication_date": args.date,
"publisher": "California Institute of Technology",
"related_identifiers": [
{
"identifier": "https://tech.caltech.edu/",
"relation_type": {"id": "ispublishedin"},
"resource_type": {"id": "publication-newspaper"},
"scheme": "url",
}
],
"resource_type": {"id": "publication-newspaperissue"},
"rights": [{"id": "default"}],
"subjects": [{"subject": "Caltech student newspaper"}],
"title": f"California Tech, v. {args.volume}, no. {args.issue}, {formatted_date}",
"version": "Published",
},
}
try:
response = caltechdata_write(
metadata,
token,
production=production,
authors=True,
community=community,
publish=False,
review_message=f"Template record created for California Tech by {args.actor} ",
)
print("templae created", response)
except Exception as e:
cleaned = format_error(format_exc())
print(
f"error= system error with writing metadata to CaltechAUTHORS {cleaned}"
)
else:
print(f"error= invalid harvest type: {harvest_type}")