Created
December 16, 2015 18:40
-
-
Save jasonhejna/ee7c748dcd46f13f6d3d to your computer and use it in GitHub Desktop.
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
"""Ingests a customer list from MS and helps detect / convert the fields for quicker ET ingestion""" | |
# TODO: add delete | |
import shutil | |
import os | |
import ntpath | |
FILE_PATH = raw_input('Enter the file path: ') | |
#FILE_PATH = 'testData/TCH4_B_HR_20150121011851.CSV' | |
# File path | |
PATH = os.path.dirname(os.path.abspath(FILE_PATH)) | |
FILE_NAME = ntpath.basename(FILE_PATH) | |
BACKUP_FILE = PATH + '/BACKUP_' + FILE_NAME | |
shutil.copyfile(FILE_PATH, BACKUP_FILE) | |
ET_COLS = ['SubscriberKey', 'Full_Name', 'firstname', 'LastName', | |
'NAME_FIRST', 'Email_Address', 'OrigEmail', 'CE', 'MIG', | |
'BP', 'BOUNCE_CE', 'SOURCE', 'Status', 'EM_TOUCH', | |
'CADENCE', 'MODEL_NAME', 'MODEL_CODE', 'MODEL', 'Code', | |
'MOI1', 'MOI2', 'MODEL_YEAR', 'MODEL_COLOR', 'gvar1', | |
'gvar2', 'DEALER_NAME', 'DEALER_STREET', 'DEALER_CITY', | |
'DEALER_STATE', 'DEALER_ZIP', 'DEALER_PHONE', | |
'DEALER_WEBSITE', 'DealerName', 'DealerAddress', | |
'DealerCityStateZip', 'DealerPhone', 'DealerWebsite', | |
'VehicleType', 'HTML_Emails', 'User_Defined', | |
'shipment_tracking_copy', 'shipper', 'LocateDealerURL', | |
'encodedVariable', 'engine', 'trim', 'amt_monthly', | |
'amt_apr', 'amt_due_at_signing', 'amt_msrp', | |
'amt_total_monthly', 'amt_lease_end_price', | |
'amt_per_mile', 'linkID', 'shipper_est_date', | |
'SubscriptionExpirationDate', 'UserName', | |
'Date_Subscribed', 'CustomerZip', 'DEALER_MAP_LINK', | |
'UniqueID', 'Schedule_Test_Drive_URL', 'UNIQUE_CODE', | |
'DEALER_URL', 'DEALER_EMAIL', 'gvar3', 'versions', | |
'DEALER_CODE'] | |
def mod_columns(fist_line): | |
"""Take the first line from the file, match known fields, | |
present unknown fields to the user for correction""" | |
print fist_line | |
new_fist_line = '' | |
columns = fist_line.split(';') | |
for value in columns: | |
# each row's column header | |
print 'next...' | |
if value in ET_COLS: | |
new_fist_line += value + ';' | |
continue | |
u_input = raw_input('"'+value+'" --> Enter new ET value, or leave blank to copy: ') | |
if u_input == '': | |
print value + ' : ' + value | |
else: | |
print value + ' : ' + u_input | |
usr_next = raw_input('Are you sure? Type "undo" to go back. ') | |
while usr_next == 'undo': | |
print 'redo...' | |
u_input = raw_input('"'+value+'" --> Enter new ET value, or leave blank to copy: ') | |
print value + ' : ' + u_input | |
usr_next = raw_input('Are you sure? Type "undo" to go back. ') | |
if u_input == '': | |
u_input = value | |
new_fist_line += u_input + ';' | |
# remove last char from string | |
new_fist_line = new_fist_line[:-1] | |
return new_fist_line | |
# clear file | |
open(FILE_PATH, 'w').close() | |
output = '' | |
line_count = 0 | |
with open(BACKUP_FILE, 'r') as read_file, open(FILE_PATH, 'w') as write_file: | |
"""read from newly created backup file, and write to original file""" | |
for line in read_file: | |
if line_count == 0: | |
write_file.write(mod_columns(line)) | |
print "WRITING FILE...." | |
else: | |
write_file.write(line) | |
line_count = 1 | |
read_file.close() | |
write_file.close() | |
print 'COMPLETE! +1 file mod points.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment