Skip to content

Instantly share code, notes, and snippets.

@iGEL
Forked from pbock/buergerbot.rb
Last active March 1, 2023 15:50
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 iGEL/b23304518e3e98f2a61e017e4fdb5465 to your computer and use it in GitHub Desktop.
Save iGEL/b23304518e3e98f2a61e017e4fdb5465 to your computer and use it in GitHub Desktop.
Bürgerbot: Refreshes the Berlin Bürgeramt page until an appointment becomes available, then notifies you.
#!/usr/bin/env ruby
require 'watir'
require 'notify'
def log (message) puts " #{message}" end
def success (message) puts "+ #{message}" end
def fail (message) puts "- #{message}" end
def notify (message)
success message.upcase
Notify.notify 'Burgerbot', message
rescue StandardError => e
end
print "Paste URL: "
url = gets.strip
def appointmentAvailable? (b)
puts '-'*80
log 'Trying again'
b.goto url
log 'Page loaded'
link = b.element css: '.calendar-month-table:first-child td.buchbar a'
if link.exists?
link.click
notify 'An appointment is available.'
system('paplay /usr/share/sounds/freedesktop/stereo/message-new-instant.oga')
log 'Enter y to keep searching or anything else to quit.'
return gets.chomp.downcase != 'y'
else
fail 'No luck this time.'
return false
end
rescue StandardError => e
fail 'Error encountered.'
puts e.inspect
return false
end
b = Watir::Browser.new
until appointmentAvailable? b
log 'Sleeping.'
sleep 45
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment