this repo has no description
at main 955 B view raw
1#!/usr/bin/env ruby 2 3require "csv" 4require "time" 5 6def payee(r) 7 case r["Type"] 8 when "Payment" 9 r["Amount (total)"][0] == "-" ? r["To"] : r["From"] 10 when "Charge" 11 r["Amount (total)"][0] == "-" ? r["From"] : r["To"] 12 when "Standard Transfer" 13 r["Destination"] 14 else 15 end 16end 17 18def date(r) 19 Time.parse(r["Datetime"]).to_date.iso8601 20end 21 22infile = ARGV.first || "venmo_statement.csv" 23outfile = File.basename(infile, File.extname(infile)) + "_ynab4.csv" 24 25lines = File.read(infile).lines 26lines.shift until lines.first.include?("ID,") 27 28CSV.open(outfile, "wb") do |out| 29 out << %w[Date Payee Memo Amount] 30 31 CSV.parse(lines.join, headers: true) do |r| 32 next unless r["ID"] 33 34 if r["Funding Source"] && r["Funding Source"] != "Venmo balance" 35 out << [date(r), r["Funding Source"], nil, r["Amount (total)"].gsub(/\A-/, "+")] 36 end 37 38 out << [ 39 date(r), 40 payee(r), 41 r["Note"], 42 r["Amount (total)"] 43 ] 44 end 45end