Skip to content

Instantly share code, notes, and snippets.

@dracodoc
Last active November 19, 2015 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dracodoc/f0eeeac91eb0d68c712c to your computer and use it in GitHub Desktop.
Save dracodoc/f0eeeac91eb0d68c712c to your computer and use it in GitHub Desktop.
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