Last active
March 15, 2023 10:26
-
-
Save leberknecht/5f6119b62144588d3d08d1caf4ba7ab7 to your computer and use it in GitHub Desktop.
berlin bürgeramt booking help
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from pyquery import PyQuery as pq | |
curl_command = "curl 'https://service.berlin.de/terminvereinbarung/termin/day/' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'Accept-Language: en,en-US;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Referer: https://service.berlin.de/dienstleistung/121469/' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Cookie: zmsappointment-session=inProgress; wt_rla=102571513503709%2C3%2C1678870510105; Zmsappointment=bdbcgshe0uar50svso3ldd0d5p' -H 'Upgrade-Insecure-Requests: 1' -H 'Sec-Fetch-Dest: document' -H 'Sec-Fetch-Mode: navigate' -H 'Sec-Fetch-Site: same-origin' -H 'Sec-Fetch-User: ?1' -H 'TE: trailers'" | |
curl_command = curl_command.replace("-H 'Accept-Encoding: gzip, deflate, br'", '') + " 2>/dev/null" | |
print("reading from website...") | |
content = os.popen(curl_command).read() | |
with open('tmppage.html', 'w') as f: | |
f.write(content) | |
if len(content) == 0: | |
print("error, no response...? oO") | |
os.system("notify-send -i security-high 'BOOKING' 'Some error occured, no response'") | |
exit(1) | |
query = pq(content) | |
if len(query('table')) != 2 and "Zu viele Zugriffe" in content: | |
print("error, blocked") | |
os.system("notify-send -i security-high 'BOOKING' 'You are hammering too hard, you have been blocked :/'") | |
exit(1) | |
bookable_days_this_month = pq(query('table')[0])('td.buchbar') | |
if len(bookable_days_this_month): | |
links = [] | |
for day in bookable_days_this_month: | |
link = pq(day)('a') | |
links.append('https://service.berlin.de' + link.attr('href')) | |
print("available: {}, link: {}".format(link.text(), links[-1])) | |
print('\a') | |
os.system("notify-send -i security-high 'BOOKING' 'Something to book! {}'".format(links[-1])) | |
else: | |
print('no luck, nothing available :/') | |
Oh..sorry, i missed that. Its the first request, with a url like https://service.berlin.de/terminvereinbarung/termin/day/
So the content
variable would look like
content = os.popen("curl 'https://service.berlin.de/terminvereinbarung/termin/day/' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: en,en-US;q=0.5' --compressed -H 'Referer: https://service.berlin.de/dienstleistung/120686/' -H 'Connection: keep-alive' -H 'Cookie: zmsappointment-session=inProgress; iom_consent=00000000000000&1614316345271; ioam2018=001a95ae2fb81d7125f9fecb9:1634732944208:1604320144208:.berlin.de:3:berlin:beberlin:noevent:1629527898698:g6y8ym; wt_rla=102571313503709%2C6%2C1626174732178; Zmsappointment=hb08su34hi48k1a9luvmnoo372' -H 'Upgrade-Insecure-Requests: 1' -H 'Cache-Control: max-age=0' -H 'TE: Trailers'").read()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Delf. I loved that you came up with a solution for the awful system of appointment booking in Berlin. Thank you so much for that.
My problem? I have no idea what I'm doing.
I made a Github account just to comment you because I have no knowledge of coding. haha.
It seems you tried to explain it in detail, but I only got to the step of opening the network tab, not really sure which one is the request (a red marked one and berlin.css), and then I copy-to-hurl (cmd).
But I don't know where to go from there. I understand that I should paste it in the (PASTE_COPY_TO_CURL) in your code. But where I use that entire code? I currently have it paste in a notepad >.< (I have tried to paste it in the Windows Command Promt)
Could you help me explaining that to a more retarded person?
Sorry if I bother you... I'm just a person trying to get an appointment.
Thank you anyway!
PS: I'm on Windows 10 and using Google Chrome