Skip to content

Instantly share code, notes, and snippets.

@eric
Created June 15, 2011 01:01
Show Gist options
  • Save eric/1026282 to your computer and use it in GitHub Desktop.
Save eric/1026282 to your computer and use it in GitHub Desktop.
Find out when a #newbeatport code is available
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
require 'notifo'
class BeatportBetaNotifier
SLEEP_TIMEOUT = 10
BEATPORT_URL = 'http://beta.beatport.com/beta'
def initialize(api_token, username)
@api_token = api_token
@username = username
@notifier = Notifo.new(username, api_token)
@notifier.subscribe_user(username)
end
def check
open(BEATPORT_URL) do |io|
Nokogiri.parse(io).css('.codes-available .codes').text.to_i
end
end
def notify(message)
@notifier.post(@username, message)
end
def run
loop do
if (available_codes = check) > 0
notify("Beatport beta codes available: #{available_codes}")
end
sleep SLEEP_TIMEOUT
end
end
end
notifier = BeatportBetaNotifier.new(ARGV[0], ARGV[1])
notifier.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment