Created
June 11, 2012 02:50
-
-
Save bjeanes/2908270 to your computer and use it in GitHub Desktop.
How much have I spent on amazon.com?
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
require 'rubygems' | |
require 'mechanize' | |
require 'date' | |
email = ARGV.shift | |
password = ARGV.shift || print('Password: ') || gets.chomp | |
# TODO: | |
# * record average product price | |
# * histogram of purchase volume | |
class Object | |
def try(method) | |
send(method) unless nil? | |
end | |
end | |
agent = Mechanize.new { |a| a.user_agent_alias = 'Mac Safari' } | |
orders_page = agent.get("https://www.amazon.com/gp/css/history/orders/view.html") | |
orders_page = orders_page.form_with(:id => "ap_signin_form") do |log_in| | |
log_in.email = email | |
log_in.password = password | |
end.submit | |
orders_page.form_with(:id => 'order-dropdown-form') do |filter| | |
filter.field_with(:id => 'orderFilter') do |select| | |
years = select.options.select { |o| o.text =~ /placed in \d{4}/ }.map(&:value).sort | |
orders = years.map do |year| | |
select.value = year | |
page = filter.submit | |
pages = [page] | |
pages << page while page = page.link_with(text: /Next /).try(:click) | |
pages.map { |page| page.search('#cs-orders .action-box') } | |
end | |
total = orders.flatten.map do |order| | |
order.search(".price").text.strip.sub('$', '').to_f | |
end.reduce(&:+) | |
puts "Total: #{'$%.02f' % total}" | |
end | |
end |
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
# Download report from https://www.amazon.com/gp/b2b/reports and run this script with the CSV as the only argument. | |
cat $* | cut -d, -f14 | grep -v Sub | xargs | tr ' ' '+' | bc |
Hahah... for me it was $11k-ish over the last 18 months. Not as high as I expected, honestly...
I added a shell script version that does the same thing but in one line. Much nicer.
Hi! Bjeanes how can i find your bash script? @bjeanes thanks!
It's the second file in this gist. But this is over 10 years old so I doubt it still works because Amazon probably changed the format of their CSVs. Not to mention, there are far better CSV processing tools in the command line than what I came up with a decade ago!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can has end numbers? :D