Skip to content

Instantly share code, notes, and snippets.

@pbock
Last active April 22, 2024 10:58
Show Gist options
  • Save pbock/3ab260f3862c350e6b5f to your computer and use it in GitHub Desktop.
Save pbock/3ab260f3862c350e6b5f 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-webdriver'
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 appointmentAvailable? (b)
url = 'http://service.berlin.de/terminvereinbarung/termin/tag.php?termin=1&dienstleister%5B%5D=122210&dienstleister%5B%5D=122217&dienstleister%5B%5D=122219&dienstleister%5B%5D=122227&dienstleister%5B%5D=122231&dienstleister%5B%5D=122238&dienstleister%5B%5D=122243&dienstleister%5B%5D=122252&dienstleister%5B%5D=122260&dienstleister%5B%5D=122262&dienstleister%5B%5D=122254&dienstleister%5B%5D=122271&dienstleister%5B%5D=122273&dienstleister%5B%5D=122277&dienstleister%5B%5D=122280&dienstleister%5B%5D=122282&dienstleister%5B%5D=122284&dienstleister%5B%5D=122291&dienstleister%5B%5D=122285&dienstleister%5B%5D=122286&dienstleister%5B%5D=122296&dienstleister%5B%5D=150230&dienstleister%5B%5D=122301&dienstleister%5B%5D=122297&dienstleister%5B%5D=122294&dienstleister%5B%5D=122312&dienstleister%5B%5D=122314&dienstleister%5B%5D=122304&dienstleister%5B%5D=122311&dienstleister%5B%5D=122309&dienstleister%5B%5D=317869&dienstleister%5B%5D=324433&dienstleister%5B%5D=325341&dienstleister%5B%5D=324434&dienstleister%5B%5D=324435&dienstleister%5B%5D=122281&dienstleister%5B%5D=324414&dienstleister%5B%5D=122283&dienstleister%5B%5D=122279&dienstleister%5B%5D=122276&dienstleister%5B%5D=122274&dienstleister%5B%5D=122267&dienstleister%5B%5D=122246&dienstleister%5B%5D=122251&dienstleister%5B%5D=122257&dienstleister%5B%5D=122208&dienstleister%5B%5D=122226&anliegen%5B%5D=120686&herkunft=%2Fterminvereinbarung%2F'
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.'
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 30
end
@goekhanak
Copy link

brilliant idea however when i try to execute it I git the following error

ruby ~/Programs/buergerbot.rb
/home/gaksakalli/Programs/buergerbot.rb:9: invalid multibyte char (US-ASCII)
/home/gaksakalli/Programs/buergerbot.rb:9: invalid multibyte char (US-ASCII)
/home/gaksakalli/Programs/buergerbot.rb:9: syntax error, unexpected $end, expecting keyword_end
... -e 'Display notification "Bürgerbot" with title "%s"'' %...
... ^

My ruby version

$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

What I am missing, in btw. I have no experience with ruby.

@tokhi
Copy link

tokhi commented May 26, 2016

I made some refactoring and its working now, you can find it here: https://gist.github.com/tokhi/5ea4c6c2d04ad0f0035c

@xuio
Copy link

xuio commented Jan 19, 2021

I did a very hacky edit to support notifying the user via Telegram: https://gist.github.com/xuio/297e16b84d700314241393e8f3aa42f3

maybe it is useful to someone

@pbock
Copy link
Author

pbock commented Jan 19, 2021

Oh wow, this thing still exists! I now live in a magical place where most admin stuff can be done online, but I’m happy (and shocked) to see that this is still useful to people.

@easingthemes
Copy link

Still useful :), thanks.

@ldelaporte
Copy link

Thanks! Still useful. For Linux users: use notify instead of the applescript notifications:
require 'notify' and Notify.notify 'Burgerbot', message instead of system 'osascript -e \'Display notification Burgerbot with title "%s"\'' % message

@noslav
Copy link

noslav commented Aug 4, 2021

confirmed this works! just watch out to not get rate limited <60 seconds wait time.

@ren0x
Copy link

ren0x commented Aug 10, 2021

It works. It took me around 1 hour to find one to two appointments (I searched Berlin-wide).
Sehr geil, danke!

@MKyhos
Copy link

MKyhos commented Sep 14, 2021

Thanks a lot for the script, still really useful! I adapted it a bit to send me a telegram notification as well on success 🤓

@drorata
Copy link

drorata commented Oct 28, 2021

Amazing! @MKyhos can you share more details how you connected it to Telegram?

Moreover, is there a way to bypass the CAPTCHA?

NB: I found this fork which uses Telegram. Didn't try it yet.

@christwolf
Copy link

does anyone know if there is a bot like this for the auslanderbehörde?

@basarozcan
Copy link

does anyone know if there is a bot like this for the auslanderbehörde?

did you find anyhing?

@christwolf
Copy link

christwolf commented Jul 19, 2022 via email

@pbock
Copy link
Author

pbock commented Jul 19, 2022

I’m afraid I can’t really offer any advice, only sympathy for having to deal with the Ausländeramt. 😣

@RustyNa1l
Copy link

Some of the services seem to have changed. For example Reisepass beantragen is now 121151 instead of 120703.
120703 is now Personalausweis beantragen.
Would be great if someone could update the telegram bot!
Thanks

@gscabola
Copy link

does anyone know if there is a bot like this for the auslanderbehörde?

Hey I'm using this it's working fine besides that is very difficult even for the bot, but at least can work without stop.
Just need to make some changes on selenium to choose your options, I used the Selenium IDE chrome extension to find the right objects.

https://github.com/capital-G/berlin-auslanderbehorde-termin-bot

@nonITguy11
Copy link

Hi guys there are alot of non IT people like me outside and we have do not understand all these codes and people earning money selling appointments on Telegram. Could someone please explain the steps for those beginner/dummies level? What should we install and where to click? I will thank then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment