Skip to content

Instantly share code, notes, and snippets.

@ruthtillman
Created August 1, 2017 14:01
Show Gist options
  • Save ruthtillman/3d035635db0ef50a6ce68d5276f92de7 to your computer and use it in GitHub Desktop.
Save ruthtillman/3d035635db0ef50a6ce68d5276f92de7 to your computer and use it in GitHub Desktop.
A gist to detect whether the group of records has an editor key, if the editor key exists, if the editor key doesn't exist for that particular group we add it (because this should have one), and adds this editor if we have nothing.
import glob, json
files = glob.glob("*.jsonld")
for fileName in files:
with open(fileName, "r") as record:
recorddata = json.loads(record.read())
if recorddata.has_key("hydra:hasEditorGroup"):
if recorddata[u"hydra:hasEditorGroup"] == {u'@id': u'und:[redacted]'}:
print 'true'
else:
recorddata[u"hydra:hasEditorGroup"] = {u'@id': u'und:[redacted]'}
newfile = "new-" + fileName
with open(newfile, "w") as outfile:
json.dump(recorddata, outfile, sort_keys=True, indent=4)
else:
recorddata[u"hydra:hasEditorGroup"] = {u'@id': u'und:[redacted]'}
newfile = "new-" + fileName
with open(newfile, "w") as outfile:
json.dump(recorddata, outfile, sort_keys=True, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment