Skip to content

Instantly share code, notes, and snippets.

@suminb
Created August 22, 2014 19:24
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 suminb/c90d2ebadb968d42c875 to your computer and use it in GitHub Desktop.
Save suminb/c90d2ebadb968d42c875 to your computer and use it in GitHub Desktop.
Data pre-processor for Moneydance
import csv
import sys
import time
DATE_COLUMN = 1
DESCRIPTION_COLUMN = 6
DEBIT_COLUMN = 4
CREDIT_COLUMN = 5
reader = csv.reader(sys.stdin)
# Skip the header line
next(reader, None)
for row in reader:
date_value = time.strptime(row[DATE_COLUMN], '%Y-%m-%d')
date_formatted = time.strftime('%Y-%m-%d', date_value)
debit_raw = row[DEBIT_COLUMN].replace(',', '')
credit_raw = row[CREDIT_COLUMN].replace(',', '')
debit = int(debit_raw) if debit_raw != '' else 0
credit = int(credit_raw) if credit_raw != '' else 0
amount = credit - debit
print('{}\t{}\t{}'.format(date_formatted, row[DESCRIPTION_COLUMN], amount))
import csv
import sys
import time
for row in csv.reader(sys.stdin):
timestamp = time.strptime(row[0], '%Y/%m/%d %H:%M')
date = time.strftime('%Y-%m-%d', timestamp)
amount = -float(row[3])
print('{}\t{}\t{}\t{}'.format(date, row[1], row[2], amount))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment