Last active
December 15, 2015 07:39
-
-
Save terenced/5224926 to your computer and use it in GitHub Desktop.
Quick and dirty script to watch prices on refurbished Mac Mini on Apple.ca.
Sends an email (via gmail) when it finds one under the threshold price.
Will most likely set it up in a cron
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
require 'gmail' | |
require 'open-uri' | |
require 'nokogiri' | |
product_url = "http://store.apple.com/ca/browse/home/specialdeals/mac/mac_mini" | |
username = 'GMAIL USER NAME' | |
password = 'PASSWORD, DUH!' | |
email = "[email protected]" | |
threshold = 600 # How much you would like to spend | |
def notify(username, password, email, product_url) | |
# TODO: Check to see if we already sent an email today O_o | |
Gmail.new(username, password) do |gmail| | |
gmail.deliver do | |
to email | |
from email | |
subject "Found one cheap enough" | |
body product_url | |
end | |
end | |
end | |
doc = Nokogiri::HTML(open(product_url)) | |
doc.xpath("//span[@itemprop='price']").each do |element| | |
price = element.inner_html.strip.gsub '$', '' | |
if not price.empty? | |
if price.to_i <= threshold | |
puts "found once at $#{price} that is less than $#{threshold}" | |
notify(username, password, email, product_url) | |
break; | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment