Created
February 5, 2015 16:08
-
-
Save leigh-johnson/23655117a34b0e94df3f to your computer and use it in GitHub Desktop.
Wellness Security leads data
This file contains hidden or 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
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