Skip to content

Instantly share code, notes, and snippets.

@mugli
Last active February 8, 2023 19:55
Show Gist options
  • Save mugli/f538e8fb0554267c1028068b75e17c59 to your computer and use it in GitHub Desktop.
Save mugli/f538e8fb0554267c1028068b75e17c59 to your computer and use it in GitHub Desktop.
Little bash script to repeatedly check if any appointment slot is available for Anmeldung (apartment registration) in Berlin
#!/bin/bash
# Check if xidell is present (required for extracting from webpage using xpath)
if ! command -v xidel &> /dev/null
then
printf "\n\nCould not find xidel \n\n"
echo "You can install it with (on a mac):"
echo "brew install xidel"
exit
fi
FULL_URL=$(xidel --silent https://service.berlin.de/dienstleistung/120686/ --extract '//*[@id="top"]/div[2]/div/div/div/div[4]/div[4]/div[1]/div/div[2]/div/a/@href')
DELAY_SEC=600
PATTERN="An diesem Tag einen Termin buchen"
function show_notification {
# Show notification on macOS when osascript is present, otherwise print to console
if ! command -v osascript &> /dev/null
then
osascript -e 'display notification "Termin slot available for Anmeldung!"'
else
echo "Termin slot available for Anmeldung!"
fi
}
while true
do
slot_exists=$(wget "${FULL_URL}" -qO- | grep -c "${PATTERN}")
[[ $slot_exists -gt 0 ]] && show_notification && echo "$(date): $slot_exists slots available now!"
sleep ${DELAY_SEC}
done
@eduardosanzb
Copy link

Hello peps, does anyone have an updated version of this? plsssss

@eduardosanzb
Copy link

I can dockerize this, but I'd rather not do the script on my own.

@eduardosanzb
Copy link

FROM debian:9-slim

RUN apt-get update \
  && apt-get install vim -y \
  && apt-get install wget libssl-dev -y --no-install-recommends \
  && wget -qO xidel.deb https://downloads.sourceforge.net/project/videlibri/Xidel/Xidel%200.9.8/xidel_0.9.8-1_amd64.deb --no-check-certificate \
  && dpkg -i xidel.deb \
  && rm -f xidel.deb \
  && rm -rf /var/lib/apt/lists/*



COPY . /app

WORKDIR /app
ENTRYPOINT ["/bin/bash", "appointment.sh"]
#!/bin/bash

# Check if xidell is present (required for extracting from webpage using xpath)

FULL_URL=$(xidel --silent https://service.berlin.de/dienstleistung/120686/ --extract '//*[@id="top"]/div[2]/div/div/div/div[4]/div[4]/div[1]/div/div[2]/div/a/@href')
DELAY_SEC=600

PATTERN="An diesem Tag einen Termin buchen"

function show_notification {
  # Show notification on macOS when osascript is present, otherwise print to console
  echo "Termin slot available for Anmeldung!"
}

while true
do
  echo "Trying now $(date +"%D %T")"
  slot_exists=$(wget "${FULL_URL}" -qO- | grep -c "${PATTERN}")
  [[ $slot_exists -gt 0 ]] && show_notification && echo "$(date):    $slot_exists slots available now!"
  sleep ${DELAY_SEC}
done

@eduardosanzb
Copy link

Just realised, they changed the website, sucks... why is so hard to get an appointment here!

@nwehrhan
Copy link

I made a version without xidel inspired by this script. Star if it helps you :) https://github.com/nwehrhan/berlin

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