Skip to content

Instantly share code, notes, and snippets.

@mugli
Last active February 8, 2023 19:55
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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
@cassmtnr
Copy link

The website was changed, can we have a update on this maybe?

@marceloboeira
Copy link

we could create a docker image, then you simply docker run it regardless of the host.

@mugli
Copy link
Author

mugli commented Jul 22, 2020

@cassianomon I have updated the script to fetch FULL_URL automatically from the page.

@vrcca
Copy link

vrcca commented Aug 14, 2020

@mugli I didn't want to install wget, so I included this function:

function count_slots {
    if ! command -v wget &> /dev/null
    then # uses curl
        echo $(curl -L --silent "${FULL_URL}" | grep -c "${PATTERN}")
    else
        echo $(wget "${FULL_URL}" -qO- | grep -c "${PATTERN}")
    fi
}

Also I added the FULL_URL to echo, so I don't lose time looking for it:

while true
do
    slot_count=$(count_slots)
    echo "$(date):    $slot_count"
    [[ $slot_count -gt 0 ]] && echo "$(date):    $slot_count slots available now! Access here: ${FULL_URL}" && show_notification
    sleep ${DELAY_SEC}
done

In show_notification I added sound notification:

say '"Attention! Attention! Attention! Termin slot available for Anmeldung!"'

@maufranchini
Copy link

⚠️ In brew, xidel has been disabled because it is not maintained upstream! +1 for docker image idea 🚀 🐳

@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