Skip to content

Instantly share code, notes, and snippets.

@aferriss
Last active March 7, 2016 23:34
Show Gist options
  • Save aferriss/c62ae3fe7d6c6611f248 to your computer and use it in GitHub Desktop.
Save aferriss/c62ae3fe7d6c6611f248 to your computer and use it in GitHub Desktop.
Formatting bad processing docs.
import sys
import re
from BeautifulSoup import BeautifulSoup
def processFile(filename):
print "reading and writing from: " + str(filename)
file = open(filename, "r+")
#lines = file.readlines()
#lines.insert(-1, "-->")
handler = open(filename).read()
soup = BeautifulSoup(handler)
txt = '</description>'
head, sep, tail = str(soup).partition(txt)
newText = head + sep + '\n</root>'
#file.writelines(newText)
h, s, t = str(filename).partition('oldXml/')
newFile = open('edited/'+t, 'a')
newFile.writelines(newText)
print newText
processFile(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment