Skip to content

Instantly share code, notes, and snippets.

@leigh-johnson
Created February 5, 2015 16:08
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 leigh-johnson/23655117a34b0e94df3f to your computer and use it in GitHub Desktop.
Save leigh-johnson/23655117a34b0e94df3f to your computer and use it in GitHub Desktop.
Wellness Security leads data
import os
import csv
import itertools
import re
_PATH = ''
export_headers = (
'Home Phone',
'Street Address',
'Work Phone',
'Apt or Unit',
'Fax',
'City/State/Zip',
'Email',
'County',
'Contact Time',
'Currently Insured',
'Major Medical',
'Vision',
'PPO',
'Dental',
'Point of Service',
'Maternity',
'Prescription',
'First Name',
'Last Name',
'Date of Birth',
'Gender',
'Height [Feet / Inches]',
'Weight',
'US Resident',
'Education',
'Ever Military',
'Occupation',
'Expectant Mother of Father',
'NoTobacco Use For the Past 12 months')
#re.split(r'[:\t]+', (line.strip('-\n\r')))
#(line.replace('\t', '\n')).strip('-\n\r')).split(': ')
def convertTab(myfile):
f1 = open(myfile, 'r')
f2 = open(myfile+'.tmp', 'w')
for line in f1:
f2.write(line.replace('\t', '\n'))
f1.close()
f2.close()
def writeAll(myfile):
in_file = open(myfile+'.tmp', 'r')
stripped = (((line.strip('-\n\r')).replace(
',','/')).split(': ') for line in in_file)
lines = (line for line in stripped if line)
row = []
for line in stripped:
if line[0] in export_headers:
row.append(line[1])
print row
with open('wellness_security_leads.csv', 'a') as out_file:
writer = csv.writer(out_file)
writer.writerow(row)
in_file.close()
myfile = open('wellness_security_leads.csv', 'w')
writer = csv.writer(myfile)
writer.writerow(export_headers)
for i in os.listdir(_PATH):
convertTab(_PATH+i)
writeAll(_PATH+i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment