Last active
December 11, 2015 23:38
-
-
Save ollieglass/4677757 to your computer and use it in GitHub Desktop.
Capital One credit card CSV importer from my personal finance mini-hackathon http://ollieglass.com/2013/01/30/personal-finance-mini-hackathon
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
for filename in os.listdir(path): | |
reader = csv.reader(open(path + filename), dialect=csv.excel) | |
headers = reader.next() | |
for row in reader: | |
m, created = Merchant.objects.get_or_create(name=row[3]) | |
# lose the £ symbol and minus sign, cast to float | |
if row[2][0] == '-': | |
billing_amount = 0 - float(row[2][2:]) | |
else: | |
billing_amount = float(row[2][1:]) | |
t, created = Transaction.objects.get_or_create( | |
# parser from dateutil = brill | |
transaction_date = parser.parse(row[0], dayfirst=True), | |
posting_date = parser.parse(row[1], dayfirst=True), | |
billing_amount = billing_amount, | |
merchant = m, | |
merchant_raw = row[3], | |
merchant_town = row[4], | |
merchant_county = row[5], | |
merchant_postcode = row[6], | |
reference_number = row[7], | |
debit_credit_flag = row[8], | |
sicmcc_code = row[9], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment