Created
August 1, 2017 14:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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