From 8b5bfd236da07d0eac12f16abc21786d919c0d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Thu, 18 Feb 2021 13:50:13 +0100 Subject: [PATCH] feat(makanek): run praesenzlehre-berlin.de liveticker --- systems/makanek/configuration.nix | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/systems/makanek/configuration.nix b/systems/makanek/configuration.nix index 4b924f3..8c574e4 100644 --- a/systems/makanek/configuration.nix +++ b/systems/makanek/configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ lib, config, pkgs, ... }: let inherit (import ) kieran; in @@ -64,4 +64,31 @@ in }; environment.systemPackages = [ pkgs.vim pkgs.git pkgs.tmux ]; + + systemd.services.praesenzlehre = { + description = "Live Ticker zu praesenzlehre-berlin.de"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + path = [ pkgs.curl pkgs.pup ]; + environment.BOT_TOKEN = lib.strings.fileContents ; + script = '' + notify() { + curl -sSL -X POST -H 'Content-Type: application/json' \ + -d "{\"chat_id\": \"@praesenzlehre_berlin\", \"text\": \"$*\"}" \ + "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" + } + + count=0 + + while true; do + new_count="$(curl -sSL https://praesenzlehre-berlin.org/ | pup '.dk-speakout-signature-count span text{}')" + if [ "$new_count" -gt "$count" ]; then + echo "$new_count" + notify "$new_count Unterzeichner:innen!" + count="$new_count" + fi + sleep 300 + done + ''; + }; }