Skip to content

Instantly share code, notes, and snippets.

@asiansteev
Last active August 29, 2015 14:04
Show Gist options
  • Save asiansteev/c79f2dea5ad24908997a to your computer and use it in GitHub Desktop.
Save asiansteev/c79f2dea5ad24908997a to your computer and use it in GitHub Desktop.
hasbrotoyshop checker
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
@chaserx
Copy link

chaserx commented Jul 29, 2014

page_changed?

@cheshire137
Copy link

Can you mark this as Ruby code, so we get syntax highlighting?

@cheshire137
Copy link

Typio line 28

@cheshire137
Copy link

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