Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/indirect/dotfiles. strap.mikemcquaid.com
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546#!/usr/bin/env ruby
require "csv"require "time"
def payee(r) case r["Type"] when "Payment" r["Amount (total)"][0] == "-" ? r["To"] : r["From"] when "Charge" r["Amount (total)"][0] == "-" ? r["From"] : r["To"] when "Standard Transfer" r["Destination"] else endend
def date(r) Time.parse(r["Datetime"]).to_date.iso8601end
infile = ARGV.first || "venmo_statement.csv"outfile = File.basename(infile, File.extname(infile)) + "_ynab4.csv"
lines = File.read(infile).lineslines.shift until lines.first.include?("ID,")
CSV.open(outfile, "wb") do |out| out << %w[Date Payee Memo Amount]
CSV.parse(lines.join, headers: true) do |r| next unless r["ID"]
if r["Funding Source"] && r["Funding Source"] != "Venmo balance" out << [date(r), r["Funding Source"], nil, r["Amount (total)"].gsub(/\A-/, "+")] end
out << [ date(r), payee(r), r["Note"], r["Amount (total)"] ] endend