Created
January 9, 2012 15:43
-
-
Save luiscberrocal/1583481 to your computer and use it in GitHub Desktop.
Clean White Spaces for Blogger
This file contains 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
## By: L. C. Berrocal | |
import sys; | |
fd = open(sys.argv[1]) | |
contents = fd.readlines() | |
fd.close() | |
new_contents = [] | |
of = open(sys.argv[2], "w") | |
print "Eliminanting white spaces from " + sys.argv[1] + " to " + sys.argv[2] | |
# Get rid of empty lines | |
pre = False | |
line_num = 0 | |
for line in contents: | |
line_num += 1 | |
find_open_pre = "<pre>" in line | |
find_close_pre = "</pre>" in line | |
if find_open_pre: | |
print "PRE FOUND OPEN " + str(line_num) | |
pre = True | |
if find_close_pre: | |
print "PRE FOUND CLOSE " + str(line_num) | |
pre = False | |
if not pre: | |
# Strip whitespace, should leave nothing if empty line was just "\n" | |
if not line.strip(): | |
continue | |
# We got something, save it | |
else: | |
new_contents.append(line.rstrip('\n')) | |
else: | |
new_contents.append(line) | |
of.writelines(new_contents) | |
of.close | |
print "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment