Skip to content

Instantly share code, notes, and snippets.

@defuse
Created March 15, 2014 18:51
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 defuse/9572043 to your computer and use it in GitHub Desktop.
Save defuse/9572043 to your computer and use it in GitHub Desktop.
Paypal Download.csv processor
# WARNING! There is no warranty. This script might not work!
FILE = "Download.csv"
rows = []
File.open( FILE ) do |f|
rows = f.readlines()
end
rows = rows[1..-1]
rows.map! do |row|
row = row.force_encoding("binary")
split = row.split('",').map { |col| col[1..-1] }
{
date: split[0],
time: split[1],
timezone: split[2],
name: split[3],
type: split[4],
status: split[5],
currency: split[6],
gross: split[7].gsub(',', '').to_f,
fee: split[8].gsub(',', '').to_f,
net: split[9].gsub(',', '').to_f,
# TODO: Add the other columns.
}
end
spent = 0
got = 0
rows.each do |row|
if row[:gross] < 0
unless ["Currency Conversion", "Withdraw Funds to a Bank Account"].include? row[:type]
p row
spent += row[:gross].abs
end
else
if ["Donation Received", "Payment Received"].include? row[:type]
got += row[:gross]
end
end
end
puts "Spent: #{spent}"
puts "Got: #{got}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment