Created
February 6, 2015 01:51
-
-
Save alliejones/bdf6082ee5bec5249f79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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