Skip to content

Instantly share code, notes, and snippets.

Last active Oct 5, 2015
What would you like to do?
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],) )
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
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