-
-
Save mugli/f538e8fb0554267c1028068b75e17c59 to your computer and use it in GitHub Desktop.
#!/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 |
we could create a docker image, then you simply docker run
it regardless of the host.
@cassianomon I have updated the script to fetch FULL_URL automatically from the page.
@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!"'
Hello peps, does anyone have an updated version of this? plsssss
I can dockerize this, but I'd rather not do the script on my own.
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
Just realised, they changed the website, sucks... why is so hard to get an appointment here!
I made a version without xidel inspired by this script. Star if it helps you :) https://github.com/nwehrhan/berlin
The website was changed, can we have a update on this maybe?