aachen.de corona incidence tracker matrix bot
The snippet can be accessed without any authentication.
Authored by
Kim Brose
- can be run as a cron job
- posts only if the site has updated since last time by storing the last version of the page
- posts only if the relevant parts of the site changed (aachen incidence)
- inserts the current date in the announcement, even though the numbers might not be updated then (but usually coincidentally they are...)
- tracks the high score (global peak since first run)
requires https://github.com/caronc/apprise python program installed to post to matrix
disclaimer: this is horrible code
corona.sh 3.65 KiB
#!/usr/bin/env bash
[ -f .last-execution ] && last="$(<.last-execution)"
[ -f .lastscore ] && tendency="$(<.lastscore)"
[ -f .highscore ] && highscore="$(<.highscore)"
#[ -f .last-page ] && last-page="$(<.last-page)"
[[ "$last" != "" ]] || last="$(LC_ALL=de_DE.utf8 date +'%A, %-d. %B %Y') -d'yesterday'"
[[ "$tendency" != "" ]] || tendency=0
[[ "$highscore" != "" ]] || highscore=0
today="$(LC_ALL=de_DE.utf8 date +'%A, %-d. %B %Y')"
#if [[ "$last" == "$today" ]]
#then
# echo "quitting: heute schon gesendet"
# exit 0
#fi
site="https://www.aachen.de/DE/stadt_buerger/notfall_informationen/corona/aktuelles/index.html"
wholepage="/tmp/corona_neu"
curl -s -L --output "$wholepage" "$site"
if diff ".last-page" "$wholepage" > /dev/null 2>&1
then
echo "quitting: seite nicht aktualisiert"
exit 0
else
mv "$wholepage" ".last-page"
fi
updated=$(curl -s -L "$site" 2>/dev/null | tr -d '\r' | grep -E "Aktuelle Lage.+(Montag|Dienstag|Mittwoch|Donnerstag|Freitag|Samstag|Sonntag)" | sed 's/.*Aktuelle Lage Stadt und StädteRegion Aachen zum Corona-Virus, \(.\+ 202[0-9]\).*/\1/g')
echo "updated: $updated"
incidence=$(curl -s -L "$site" 2>/dev/null | tr -d '\r' | grep 'RKI.\+weist.\+Inzidenz.\+aus' | sed 's%<[^>]*>%%g')
echo "incidence"
echo "$incidence"
score=$(echo "$incidence" | sed 's/.*Das .*RKI.\+ Inzidenz von \([0-9.]\+\) aus\. Die Sieben-Tage-Inzidenz des Landes liegt bei [0-9.]\+\..*/\1/' | sed 's/\.//g')
echo "score"
echo "$score"
aachen=$(echo "$incidence" | sed 's/.*\(Das .*RKI.\+ Inzidenz von [0-9.]\+ aus\)\. Die Sieben-Tage-Inzidenz des Landes liegt bei [0-9.]\+\..*/\1/')
nrw=$(curl -s -L "$site" 2>/dev/null | tr -d '\r' | grep 'Inzidenz des Landes' |sed 's/.*\(Die Sieben-Tage-Inzidenz des Landes liegt bei [0-9.]\+\.\).*/\1/')
if [[ "$last" == "$updated" ]] && [ "$tendency" -eq "$score" ]
then
echo "quitting: zahlen nicht aktualisiert"
exit 0
fi
links="<a href=\"$site\">aachen.de/corona</a> | <a href=\"https://www.staedteregion-aachen.de/de/navigation/aemter/oeffentlichkeitsarbeit-s-13/aktuelles/pressemitteilungen/aktuelle-pressemitteilungen/coronavirus\">staedteregion-aachen.de/corona</a> | <a href=\"https://oecher.info\">oecher.info</a> | <a href=\"https://experience.arcgis.com/experience/478220a4c454480e823b17327b2bf1d4/page/page_1/\">RKI dashboard</a> | <a href=\"https://covid-karte.de\">covid-karte</a> | <a href=\"https://impfdashboard.de\">impfdashboard.de</a>"
#echo "today"
#echo "$today"
#echo "page today"
#echo "$page" | grep "$today"
#echo "nrw"
#echo "$nrw"
if [[ "$updated" != "" ]]
then
# updated="$(echo "$updated" | sed 's/.*\('"$today"'.*\)$/\1/')"
aachen="$(echo "$aachen" | awk -v awkfrom="heute" -v awkto="heute, $updated," '{gsub(awkfrom,awkto); print}')"
echo "$score" > .lastscore
incidence="${aachen} (war: ${tendency}). "
if [ "$tendency" -lt "$score" ]
then
incidence="${incidence}📈"
elif [ "$tendency" -eq "$score" ]
then
incidence="${incidence}"
else
incidence="${incidence}📉"
fi
if [ "$score" -gt "$highscore" ]
then
incidence="${incidence}<br>🎰 <strong>High Score!</strong> ✨ (war: ${highscore})"
echo "$score" > .highscore
fi
if [[ "$aachen" == "" ]]
then
incidence="(Sieht aus als sei die Website der Stadt ausnahmsweise mal kaputt.)"
fi
incidence="${incidence}<br>${nrw}"
echo "$today" > .last-execution
# echo "$wholepage" > .last-page
# echo "$incidence"
apprise -b "${incidence}<br>${links}" 'matrixs://apprise:$password@example.org/$room'
fi
Please register or sign in to comment