Last active
July 15, 2020 10:02
-
-
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
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
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