Skip to content

Instantly share code, notes, and snippets.

@coreyward
Created November 21, 2012 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreyward/4127081 to your computer and use it in GitHub Desktop.
Save coreyward/4127081 to your computer and use it in GitHub Desktop.
I wanted to get an early bird reward for a Kickstarter project, and sometimes people abandon them to switch tiers or un-pledge, so I slapped some code together using Typhoeus, Nokogiri, and Twilio to retrieve the Kickstarter page, grab the relevant reward
# coding: utf-8
require 'rubygems'
require 'twilio-ruby'
require 'nokogiri'
require 'typhoeus'
# Setup Request
url = "http://www.kickstarter.com/projects/martinkallstrom/memoto-lifelogging-camera"
selector = "#what-you-get li:nth-child(4)"
current_text = "\nPledge $199 or more\n\n\n\n\n1000 backers\n\n\nSold out\n\n\n\n\nEARLY BIRD SPECIAL • At $80 off of list price, be the first to get a Memoto camera in your choice of color. Choose between Arctic White, Graphite Gray and Memoto Orange PLUS get featured on the list of Memoto Friends at memoto.com.\n\n\nEstimated delivery:\nFeb 2013\n\n\n\n\n"
loop do
http = Typhoeus::Request.get(url)
doc = Nokogiri::HTML.parse(http.body)
text = doc.css(selector).first.text
if text != current_text
# Setup Twilio
account_sid = "..."
auth_token = "..."
client = Twilio::REST::Client.new account_sid, auth_token
from = "+1 1111111111" # Your Twilio number
client.account.sms.messages.create(
:from => from,
:to => "+1 1111111111",
:body => "Memoto page changed! #{url}"
)
puts "Sent message!"
raise StopIteration
else
puts "Same content; sleeping for 10 seconds"
sleep 10
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment