Skip to content

Instantly share code, notes, and snippets.

@alliejones
Created February 6, 2015 01:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alliejones/bdf6082ee5bec5249f79 to your computer and use it in GitHub Desktop.
Save alliejones/bdf6082ee5bec5249f79 to your computer and use it in GitHub Desktop.
import sys
import csv
import os
rows = []
input_file = sys.argv[1]
rows.append([ 'Date', 'Payee', 'Category', 'Memo', 'Outflow', 'Inflow' ])
with open(input_file, 'rb') as f:
reader = csv.reader(f)
for row in reader:
data = {
'date': row[0].split()[0],
'payee': row[2],
'category': '',
'memo': ''
}
amount = float(row[7])
if amount < 0:
data['inflow'] = amount * -1
data['outflow'] = ''
else:
data['inflow'] = ''
data['outflow'] = amount
rows.append([
data['date'],
data['payee'],
data['category'],
data['memo'],
data['outflow'],
data['inflow']
])
output_file = os.path.basename(input_file) + ' (YNAB format).csv'
with open(output_file, 'wb') as f:
writer = csv.writer(f)
writer.writerows(rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment