Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jgstew committed Mar 13, 2023
1 parent 04c9fda commit 3dfc844
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion examples/fixlet_add_mime_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def main():

fixlet_site_name = str(result.besdict["Query"]["Result"]["Answer"])

# escape `/` in site name, if applicable
# do spaces need escaped too? `%20`
fixlet_site_name = fixlet_site_name.replace("/", "%2f")

print(fixlet_site_name)
Expand All @@ -52,6 +54,7 @@ def main():

root_xml = lxml.etree.fromstring(fixlet_content.besxml)

# get first MIMEField
xml_first_mime = root_xml.find(".//*/MIMEField")

xml_container = xml_first_mime.getparent()
Expand All @@ -60,6 +63,7 @@ def main():

print(xml_container.index(xml_first_mime))

# new mime to set relevance eval to once an hour:
new_mime = lxml.etree.XML(
"""<MIMEField>
<Name>x-relevance-evaluation-period</Name>
Expand All @@ -70,12 +74,14 @@ def main():
print(lxml.etree.tostring(new_mime))

# insert new mime BEFORE first MIME
# https://stackoverflow.com/questions/7474972/append-element-after-another-element-using-lxml
xml_container.insert(xml_container.index(xml_first_mime) - 1, new_mime)

print(
"\nPreview of new XML:\n ",
lxml.etree.tostring(root_xml, encoding="utf-8", xml_declaration=True).decode(
"utf-8"
)
),
)

# TODO: PUT changed XML back to RESTAPI resource to modify
Expand Down

0 comments on commit 3dfc844

Please sign in to comment.