*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects

Updates

Merged Moser, Maximilian requested to merge dev into master
10 files
+ 668
103
Compare changes
  • Side-by-side
  • Inline
Files
10
+ 99
0
#!/usr/bin/env python3
import json
import os
import sys
def map_identifiers(identifiers):
ret = []
for k in identifiers:
val = {
"identifier": identifiers[k],
"scheme": k,
}
ret.append(val)
return ret
def map_affiliation(affiliation):
return {
"name": affiliation["name"],
"identifiers": map_identifiers(affiliation.get("identifiers", {})),
}
def map_creatibutor(creatibutor, default_role="editor"):
return {
"role": creatibutor.get("role", default_role),
"affiliations": [map_affiliation(aff) for aff in creatibutor["affiliations"]],
"person_or_org": {
"type": creatibutor["type"],
"name": creatibutor.get("name"),
"given_name": creatibutor.get("given_name"),
"family_name": creatibutor.get("family_name"),
"identifiers": map_identifiers(creatibutor.get("identifiers", [])),
},
}
def map_right(right):
return {
"link": right.get("uri"),
"id": right.get("identifier"),
"title": right.get("rights"),
}
def map_location(location):
ret = location.copy()
ret["identifiers"] = map_identifiers(location.get("identifiers", []))
return ret
# - - - - - - - - - - - #
# start doing the stuff #
# - - - - - - - - - - - #
directory = sys.argv[1] if len(sys.argv) > 1 else "outputs"
for f in os.listdir(directory):
ff = os.path.join(directory, f)
recid, ext = os.path.splitext(f)
if ext.lower() != ".json":
continue
with open(ff, "r") as data_file:
data = json.load(data_file)
new = data.copy()
for k in ["id", "pid", "conceptid", "conceptpid"]:
new.pop(k, None)
new["metadata"]["contributors"] = [
map_creatibutor(c) for c in data["metadata"].get("contributors", [])
]
new["metadata"]["creators"] = [
map_creatibutor(c) for c in data["metadata"]["creators"]
]
new["metadata"]["rights"] = [
map_right(right) for right in data["metadata"].get("rights", [])
]
new["metadata"]["locations"] = [
map_location(location) for location in data["metadata"].get("locations", [])
]
# TODO: check why this is the case
new["metadata"].pop("references", None)
# because subjects aren't supported right now (TODO: check)
new["metadata"].pop("subjects", None)
# because the identifiers may have used weird schemes in both cases
new["metadata"].pop("locations", None)
new["metadata"].pop("funding", None)
new["access"] = {"record": "public", "files": "public", "owned_by": [{"user": "1"}]}
ff = os.path.join(directory, recid + ".migrated")
with open(ff, "w") as data_file:
json.dump(new, data_file)
Loading