Created
July 2, 2015 20:09
-
-
Save cgopalan/9d90fc6ab6adf9724fdc to your computer and use it in GitHub Desktop.
This file contains 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 csv | |
import json | |
input_file = 'PROD_CUSTOMERS_GOOD.csv' | |
output_file = 'wowcher_customer_creation_formatted.json' | |
with open(input_file) as infile: | |
infile.readline() | |
with open(output_file, 'w') as outfile: | |
r = csv.reader(infile) | |
for row_num, row in enumerate(r, start=1): | |
# Number of fields must be 37. | |
if len(row) != 37: | |
print(row_num, len(row)) | |
else: | |
d,m,y = row[29].split(' ')[0].split('/') | |
datestr = '-'.join([y,m,d]) | |
doc = {} | |
doc['id'] = row[1] | |
# doc['key'] = "email" | |
doc['vars'] = {"customer_creation_date": datestr} | |
outfile.write(json.dumps(doc)) | |
outfile.write('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment