Created
March 15, 2014 18:51
-
-
Save defuse/9572043 to your computer and use it in GitHub Desktop.
Paypal Download.csv processor
This file contains hidden or 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
# 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