Last active
August 29, 2015 14:04
-
-
Save asiansteev/c79f2dea5ad24908997a to your computer and use it in GitHub Desktop.
hasbrotoyshop checker
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 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'restclient' | |
require 'twitter' | |
require 'yaml' | |
@i = 0 | |
exclusives = { | |
url: 'http://hasbrotoyshop.com/exclusives', | |
items_count: 2} | |
other_exclusives = { | |
url: 'http://hasbrotoyshop.com/products/category/exclusives', | |
items_count: 2} | |
search = { | |
url: 'http://hasbrotoyshop.com/SearchResults.htm?SWD=magic', | |
items_count: 6} | |
pages = [exclusives, other_exclusives, search] | |
def page_changed? page | |
find_me = "#{page[:items_count]} of #{page[:items_count]} items displayed" | |
doc = Nokogiri::HTML(open(page[:url])) | |
doc.css('td.RTGray12').none?{|td| td.children.to_s == find_me } | |
end | |
def tell_me | |
p notification = "AAAAH! SOMETHING CHANGEDi!!!!!" | |
fn = File.join(File.dirname(File.expand_path(__FILE__)), 'credentials.yml') | |
credentials = YAML::load(File.open(fn)) | |
client = Twitter::REST::Client.new(credentials) | |
client.create_direct_message('@asiansteev', notification) | |
end | |
catch (:change_detected) do | |
loop do | |
pages.each do |page| | |
throw :change_detected if page_changed?(page) | |
sleep 5 | |
p "checked: #{@i += 1}" | |
end | |
end | |
end | |
tell_me |
Can you mark this as Ruby code, so we get syntax highlighting?
Typio line 28
Could use File.join(File.dirname(File.expand_path(__FILE__)), 'credentials.yml')
for your Windows friends on line 30.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
page_changed?