Skip to content

Instantly share code, notes, and snippets.

@simonvc
Created July 30, 2013 13:58
Show Gist options
  • Save simonvc/6113129 to your computer and use it in GitHub Desktop.
Save simonvc/6113129 to your computer and use it in GitHub Desktop.
Here's how to process amazon csv format.
#!/usr/bin/env python
from datetime import datetime, date
from csv import reader
from sys import argv
dateformat='%Y/%m/%d %H:%M:%S'
if __name__=='__main__':
filename = argv[1]
print "Loading from %s" % filename
f=reader(open(filename))
first_line = f.next()
second_line = f.next()
third_line = f.next()
print first_line
print second_line
print third_line
#this hideous piece of code checks to see whether amazon have added a flash line to the start of the billing line
if len(first_line) == len(third_line):
keymap=first_line
#build the dict
elif len(second_line) == len(third_line):
#build the dict
keymap=second_line
pass
else:
print "I can't process this file because i can't find the heading line that tells me what fields im going to need to import"
exit(1)
for line in reader(open(filename)):
for i in range(len(line)):
print keymap[i],"::::::>", line[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment