Created
April 11, 2009 21:59
-
-
Save kmarsh/93750 to your computer and use it in GitHub Desktop.
Check for black Mini 9's at the Dell Outlet
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
#!/usr/bin/env ruby | |
require 'pp' | |
require 'rubygems' | |
require 'mechanize' | |
require 'nokogiri' | |
PRICE_THRESHOLD = 200 | |
EMAIL_ALERT = '' # e-mail address to send alerts to | |
CELL_MAPPINGS = { | |
2 => 'ID', | |
4 => 'Price', | |
5 => 'Model', | |
6 => 'Color', | |
8 => 'OS', | |
9 => 'Screen Size', | |
10 => 'HDD', | |
11 => 'Memory', | |
16 => 'Wireless' | |
} | |
a = WWW::Mechanize.new do |agent| | |
agent.user_agent_alias = 'Mac Safari' | |
end | |
a.get('http://outlet.us.dell.com/ARBOnlineSales/topics/global.aspx/arb/online/en/InventorySearch?c=us&cs=22&l=en&lob=INSP&MODEL_DESC=Inspiron%20Mini%209%20-%20910&s=dfh') do |page| | |
search_result = page.form_with(:name => 'thisForm') do |search| | |
search.SYSTEM_COLOR = 'Obsidian Black' | |
end.submit | |
# Write the result to an HTML file for debugging | |
File.open("page.html", "w+") do |f| | |
f.puts search_result.body | |
end | |
# Parse the output | |
doc = Nokogiri::HTML(search_result.body) | |
results = [] | |
doc.css('table.tblLayout tr').each do |row| | |
result = {} | |
row.css("td").each_with_index do |cell, i| | |
result[CELL_MAPPINGS[i]] = cell.content if CELL_MAPPINGS[i] | |
end | |
results << result if result != {} && result['Price'] != "Model" | |
end | |
# Sort by price, and clean up the Output a bit | |
below_threshold = [] | |
results.sort_by {|result| result['Price'][1, 10].to_f }.each do |result| | |
output = "%s - %s, %s, %s, %s" % [result['ID'].gsub('View Details', ''), result['Price'], result['OS'].gsub('Genuine Windows ', ''), result['Memory'], result['HDD'].gsub(' Solid State Drive', '')] | |
puts output | |
if result['Price'][1, 10].to_f < PRICE_THRESHOLD | |
below_threshold << output | |
end | |
end | |
if below_threshold != [] | |
File.open('/tmp/deals', 'w+') do |f| | |
f.puts below_threshold.join("\n") | |
end | |
system("cat /tmp/deals | sendmail #{EMAIL_ALERT}") | |
end | |
end |
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
ZR7D0TJW - $309.00, XP Home, 512, 8 GB | |
Z2RYV565 - $309.00, XP Home, 1000, 8 GB | |
FXDFC365 - $309.00, XP Home, 512, 8 GB | |
0GV04CDW - $309.00, XP Home, 512, 8 GB | |
FX95JW65 - $309.00, XP Home, 1000, 8 GB | |
E6R28WT0 - $309.00, XP Home, 512, 8 GB | |
FXEEZR65 - $309.00, XP Home, 512, 8 GB | |
DDALAX15 - $379.00, XP Home, 1000, 8 GB | |
ZRBAKD8W - $379.00, XP Home, 512, 8 GB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment