Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@cassianomon

This comment has been minimized.

Copy link

@cassianomon cassianomon commented Jun 24, 2020

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

@marceloboeira

This comment has been minimized.

Copy link

@marceloboeira marceloboeira commented Jul 3, 2020

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

@mugli

This comment has been minimized.

Copy link
Owner Author

@mugli mugli commented Jul 22, 2020

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

@vrcca

This comment has been minimized.

Copy link

@vrcca 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!"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment