Skip to content

Instantly share code, notes, and snippets.

@mAu888
Created April 19, 2016 07:36
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 mAu888/130e2e7a3a7862d0ea57532c68e4b81c to your computer and use it in GitHub Desktop.
Save mAu888/130e2e7a3a7862d0ea57532c68e4b81c to your computer and use it in GitHub Desktop.
Finds an appointment for you at the Berliner Bürgeramt
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
def log (message) puts " #{message}" end
def success (message) puts "+ #{message}" end
def fail (message) puts "- #{message}" end
def notify (message)
success message.upcase
system 'osascript -e \'Display notification "Bürgerbot" with title "%s"\'' % message
rescue StandardError => e
end
def osascript(script)
system 'osascript', *script.split(/\n/).map { |line| ['-e', line] }.flatten
end
# Find the URL by searching on the website for the desired appointment type (e.g. get a passport/id card etc.) and paste the URL from the browser here
url = 'https://service.berlin.de/terminvereinbarung/termin/tag.php?termin=1&anliegen[]=121151&dienstleisterlist=122210,122217,122219,122227,122231,122238,122243,122252,122260,122262,122254,122271,122273,122277,122280,122282,122284,122291,122285,122286,122296,150230,122301,122297,122294,122312,122314,122304,122311,122309,317869,324433,325341,324434,122281,324414,122283,122279,122276,122274,122267,122246,122251,122257,122208,122226&herkunft=http%3A%2F%2Fservice.berlin.de%2Fdienstleistung%2F121151%2F'
loop do
puts 'Retrying.'
page = Nokogiri::HTML(open(url))
unbookable = page.css('.calendar-month-table:first-child td.nichtbuchbar')
bookable = page.css('.calendar-month-table:first-child td.buchbar a')
puts "There are #{unbookable.count} unbookable and #{bookable.count} bookable days this month"
bookable.collect do |item|
day = item.css('u span:first-child').first
notify("Appointment on #{day.content}th")
end
unbookable_next = page.css('.calendar-month-table:nth-child(2) td.nichtbuchbar')
bookable_next = page.css('.calendar-month-table:nth-child(2) td.buchbar a')
puts "There are #{unbookable_next.count} unbookable and #{bookable_next.count} bookable days next month"
bookable_next.collect do |item|
day = item.css('u span:first-child').first
notify("Appointment on #{day.content}th")
end
break if bookable.count > 0 || bookable_next.count > 0
wait_for = 30 + Random.rand(30)
puts "Wait for #{wait_for} seconds"
sleep wait_for
end
osascript <<-END
display notification "Found appointment" with title "Buergerbot"
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment