Last active
April 3, 2016 23:06
-
-
Save LouisStAmour/518124929a058987969d009b9257f601 to your computer and use it in GitHub Desktop.
Ruby script to convert Mint.com transactions.csv from all accounts to per-account CSVs importable to QuickBooks Online (Canada)
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
# Assumes the current directory has a file named "Mint Transactions.csv" | |
# downloaded from mint using CSV by hitting "Export" under the per-page settings on | |
# Mint's All Transactions screen. | |
# | |
# This is meant for QuickBooks Online, since the CSV format for Canadians, at least, | |
# doesn't support the 2-column approach used by Mint (first column positive amount, | |
# second column debit/credit indicator) and in QBO, transactions must be imported | |
# one CSV file per account, while it's easier to export all accounts in Mint. | |
# So this script does both conversion to a negative/positive amount and writes CSVs | |
# per account. | |
# | |
# For QuickBooks Desktop, see http://bit.ly/1PPMHbq (also has Mint export instructions) | |
# | |
# Note also that QuickBooks Self-Employed (US only) appears to offer Mint integration: | |
# https://selfemployed.uservoice.com/knowledgebase/articles/457582-import-transactions-from-mint | |
require 'csv' | |
transactions = CSV.table("Mint Transactions.csv") | |
accounts = transactions[:account_name].uniq.map do |acct| | |
{ | |
name: acct, | |
filename: acct.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')+'.csv' | |
} | |
end | |
transactions.each do |row| | |
row[:amount] *= -1 if row[:transaction_type] == 'debit' | |
end | |
transactions.delete :transaction_type | |
File.open('Mint Transactions Edited.csv', 'w') do |f| | |
f.write transactions.to_csv | |
end | |
transactions = nil | |
sleep 1 | |
accounts.each do |acct| | |
File.open(acct[:filename], 'w') do |f| | |
temp = CSV.table("Mint Transactions Edited.csv") | |
temp.delete_if {|row| row[:account_name] != acct[:name] } | |
temp.delete :account_name | |
f.write temp.to_csv | |
temp = nil | |
end | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment