Skip to content

Instantly share code, notes, and snippets.

@carj
Last active July 15, 2020 10:02
Show Gist options
  • Save carj/dbaebeb5736568acba9c757f395fe1b5 to your computer and use it in GitHub Desktop.
Save carj/dbaebeb5736568acba9c757f395fe1b5 to your computer and use it in GitHub Desktop.
Adding a new descriptive metadata template element to all assets in a folder
from xml.etree import ElementTree
from pyPreservica import *
client = EntityAPI()
folder = client.folder("723f6f27-c894-4ce0-8e58-4c15a526330e")
for child_asset in filter(only_assets, client.descendants(folder.reference)):
asset = client.asset(child_asset.reference)
xml_document = ElementTree.fromstring(client.metadata_for_entity(asset, "your-xml-namespace"))
new_Element = ElementTree.Element('{your-xml-namespace}your-element-name')
new_Element.text = "Value"
xml_document.append(new_Element)
xml_string = ElementTree.tostring(xml_document, encoding='UTF-8', xml_declaration=True).decode("utf-8")
asset = entity.update_metadata(asset, "your-xml-namespace", xml_string)
print("Updated asset: " + asset.title)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment