Skip to content

Instantly share code, notes, and snippets.

@cgopalan
Created July 2, 2015 20:09
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 cgopalan/9d90fc6ab6adf9724fdc to your computer and use it in GitHub Desktop.
Save cgopalan/9d90fc6ab6adf9724fdc to your computer and use it in GitHub Desktop.
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