Last active
September 21, 2018 17:16
-
-
Save kindly/2232655f6d950413f3788be44c864151 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 sys | |
| from lxml import etree | |
| root = etree.parse(sys.argv[1]) | |
| actual_results = {} | |
| for num, result in enumerate(list(root.iter("result"))): | |
| title = num | |
| title_element = result.find("title") | |
| if title_element is not None: | |
| narrative_element = title_element.find("narrative") | |
| if narrative_element is not None: | |
| title = narrative_element.text.strip() | |
| if title in actual_results: | |
| result_element = actual_results[title] | |
| for indicator_element in result.iter("indicator"): | |
| result_element.append(indicator_element) | |
| result.getparent().remove(result) | |
| else: | |
| actual_results[title] = result | |
| print(etree.tostring(root, pretty_print=True).decode()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment