Skip to content

Instantly share code, notes, and snippets.

@johannhof
Created February 22, 2016 17:34
Show Gist options
  • Save johannhof/61bfb41176350d66a459 to your computer and use it in GitHub Desktop.
Save johannhof/61bfb41176350d66a459 to your computer and use it in GitHub Desktop.
my burgerbot
#!/usr/bin/env ruby
# modified from https://gist.github.com/pbock/3ab260f3862c350e6b5f #
require 'watir-webdriver'
class BurgerBot
def initialize
@attempt_count = 0
@date = Time.now.to_i
end
def run
until appointment_available?
puts 'Sleeping.'
sleep 10
end
end
private
def appointment_available?
puts '-'*80
puts "Beginning attempt ##{@attempt_count += 1}"
browser.goto url
puts 'Page loaded'
link = browser.element css: '.calendar-month-table:first-child td.buchbar a'
if link.exists? # only show links once?
link.click
notify 'An appointment is available.'
puts 'Enter y to keep searching or anything else to quit.'
return gets.chomp.downcase != 'y'
else
puts 'No luck this time.'
return false
end
rescue StandardError => e
puts 'Error encountered.'
puts e.inspect
return false
end
def browser
@browser ||= Watir::Browser.new
end
def notify(message)
puts message.upcase
system 'osascript -e \'Display notification "Bürgerbot" with title "%s"\'' % message
rescue StandardError => e
end
def url
'https://service.berlin.de/terminvereinbarung/termin/tag.php'\
'?id=&buergerID=&buergername=&absagecode='\
"&Datum=#{@date}"\
'&anliegen%5B%5D=121469'\
'&dienstleister%5B%5D=122297'\
'&dienstleister%5B%5D=122301'
end
end
BurgerBot.new.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment