Skip to content

Instantly share code, notes, and snippets.

@RaghavSood
Created April 8, 2014 23:45
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 RaghavSood/10209858 to your computer and use it in GitHub Desktop.
Save RaghavSood/10209858 to your computer and use it in GitHub Desktop.
import os
import sys
import re
directory = "/Users/raghavsood/Downloads/Elections/Delhi/Analysed/Lists/"
inputdirectory = "/Users/raghavsood/Downloads/Elections/Delhi/Analysed/"
try:
os.makedirs(directory)
except OSError:
pass # already exists
for filename in os.listdir(inputdirectory):
#if counter >= 5:
# sys.exit("Done")
if filename[-4:] == '.txt':
path = inputdirectory + filename
formatone = re.compile("[a-zA-Z]{3}[0-9]{7}")
formattwo = re.compile("[a-zA-Z]{2}[\\/]{1}[0-9]{2}[\\/]{1}[0-9]{3}[\\/]{1}[0-9]{6}")
with open(path, 'r') as f:
text = f.read()
print "Indexing " + filename
output = re.findall(r'[a-zA-Z]{3}[0-9]{7}', text)
out_str = "\n".join(output)
outputtwo = re.findall(r'[a-zA-Z]{2}[\\/]{1}[0-9]{2}[\\/]{1}[0-9]{3}[\\/]{1}[0-9]{6}', text)
out_str += "\n"
out_str += "\n".join(outputtwo)
with open(directory + "/" + filename, "w") as outp:
outp.write(out_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment