Last active
October 5, 2015 00:10
-
-
Save moskewcz/7f676243b910afb80178 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 | |
import xml.etree.ElementTree as xee | |
def main( args ): | |
assert len(args) | |
if len(args) != 3: raise ValueError( "usage: %s save_in.xml save_out.xml" % (args[0],) ) | |
doc=xee.fromstring(open(args[1]).read()) | |
for node in doc.iter(): | |
#if node.text is None: node.text = " "; continue # work around TT's inability to parse <foo /> style tags | |
if node.tag != "Inv": continue # not inv node, skip | |
if node.text is None: continue # empty inv, skip | |
inv_parts = node.text.split(",") | |
new_inv_parts = [] | |
for inv_part in inv_parts: | |
if inv_part[0:2] in ["c:","r:","i:"]: | |
item_parts = inv_part.split(":")[1:] | |
item_parts = [ ip for ip in item_parts if ip ] | |
new_inv_part = inv_part[0:2] + "::".join(item_parts) | |
print( new_inv_part ) | |
new_inv_parts.append( new_inv_part ) # use edited item | |
else: | |
new_inv_parts.append( inv_part ) # not an item, don't touch | |
new_inv = ",".join(new_inv_parts) | |
#assert new_inv == node.text # for testing split/join (only valid if no edits) | |
node.text = new_inv | |
open(args[2],"w").write( xee.tostring(doc) ) | |
if __name__ == "__main__": | |
import sys | |
main( sys.argv ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment