Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
python script to split the multiple states loader script generated by PostGIS Tiger Geocoder into separate script for each state
__author__ = 'draco'
# split all states loader script into separate scripts by states.
# replace all the "set TMPDIR=..." line with ":: ---- end state ----\nset TMPDIR=..."
# then delete the first line of ":: ---- end state ----\n"
# modify the base file path and output file folder by your case.
text_file = open("e:\\Data\\all_states.bat","r")
lines = text_file.readlines()
text_file.close()
print len(lines)
sep = ":: ---- end state ----\n"
file_no = 1
temp = ""
for line in lines[0:]:
if line != sep:
temp += line
else:
state_file = open("e:\\Data\\" + str(file_no).zfill(2) + ".bat", 'w')
state_file.write(temp)
state_file.close()
temp = line
file_no += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment