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 :/') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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