1
0
mirror of https://github.com/kmein/niveum synced 2026-03-19 11:31:09 +01:00

feat(makanek): upgrade praesenzlehre to timer

This commit is contained in:
2021-02-18 17:15:07 +01:00
parent 8b5bfd236d
commit 2a5ea9700b

View File

@@ -66,29 +66,43 @@ in
environment.systemPackages = [ pkgs.vim pkgs.git pkgs.tmux ]; environment.systemPackages = [ pkgs.vim pkgs.git pkgs.tmux ];
systemd.services.praesenzlehre = { systemd.services.praesenzlehre = {
description = "Live Ticker zu praesenzlehre-berlin.de"; description = "Live Ticker zu praesenzlehre-berlin.org";
after = [ "network.target" ]; wants = [ "network.target" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
path = [ pkgs.curl pkgs.pup ]; startAt = "*:00/15";
path = [ pkgs.curl pkgs.pup pkgs.bc ];
environment.BOT_TOKEN = lib.strings.fileContents <system-secrets/telegram/kmein.token>; environment.BOT_TOKEN = lib.strings.fileContents <system-secrets/telegram/kmein.token>;
script = '' script = ''
set -efu
count_file=/tmp/praesenzlehre-berlin.org
set_count() {
echo $* > "$count_file"
}
get_count() {
cat "$count_file"
}
notify() { notify() {
curl -sSL -X POST -H 'Content-Type: application/json' \ curl -sSL -X POST -H 'Content-Type: application/json' \
-d "{\"chat_id\": \"@praesenzlehre_berlin\", \"text\": \"$*\"}" \ -d "{\"chat_id\": \"@praesenzlehre_berlin\", \"text\": \"$*\"}" \
"https://api.telegram.org/bot$BOT_TOKEN/sendMessage" "https://api.telegram.org/bot$BOT_TOKEN/sendMessage"
} }
count=0 test -f "$count_file" || set_count 0
while true; do count="$(get_count)"
new_count="$(curl -sSL https://praesenzlehre-berlin.org/ | pup '.dk-speakout-signature-count span text{}')"
if [ "$new_count" -gt "$count" ]; then new_count="$(curl -sSL https://praesenzlehre-berlin.org/ | pup '.dk-speakout-signature-count span text{}')"
echo "$new_count"
notify "$new_count Unterzeichner:innen!" if [ "$new_count" -gt "$count" ]; then
count="$new_count" diff="$(echo "$new_count - $count" | bc)"
fi echo "$new_count (+ $diff)"
sleep 300 notify "$new_count Unterzeichner:innen! (+ $diff)"
done set_count "$new_count"
fi
''; '';
}; };
} }