diff --git a/configs/default.nix b/configs/default.nix index d387da0..5e87a38 100644 --- a/configs/default.nix +++ b/configs/default.nix @@ -292,6 +292,7 @@ in { ./watson.nix ./zsh.nix ./tor.nix + ./stw-berlin.nix ./mastodon-bot.nix ]; } diff --git a/configs/stw-berlin.nix b/configs/stw-berlin.nix new file mode 100644 index 0000000..570ac69 --- /dev/null +++ b/configs/stw-berlin.nix @@ -0,0 +1,51 @@ +{ + pkgs, + config, + ... +}: { + age.secrets.stw-berlin-card-code.file = ../secrets/stw-berlin-card-code.age; + + systemd.services.stw-berlin = { + enable = true; + wants = ["network-online.target"]; + startAt = "weekly"; + serviceConfig = { + user = "kfm"; + WorkingDirectory = "/home/kfm/cloud/nextcloud/Uni/Meta/Mensa"; + LoadCredential = [ + "password:${config.age.secrets.stw-berlin-card-code.path}" + ]; + }; + script = '' + KARTEN_ID=8071859 + PASSWORT=$(cat "$CREDENTIALS_DIRECTORY"/password) + + endpoint=https://ks.stw.berlin:4433/TL1/TLM/KASVC + authorization_header='Authorization: Basic S0FTVkM6ekt2NXlFMUxaVW12VzI5SQ==' + + get_auth_token() { + ${pkgs.curl}/bin/curl -sSL "$endpoint/LOGIN?karteNr=$KARTEN_ID&format=JSON&datenformat=JSON" \ + -X POST \ + -H "$authorization_header" \ + --data-raw '{"BenutzerID":"'$KARTEN_ID'","Passwort":"'$PASSWORT'"}' \ + | ${pkgs.jq}/bin/jq -r '.[0].authToken|@uri' + } + + + get_transactions() { + ${pkgs.curl}/bin/curl -sSL "$endpoint/TRANS?format=JSON&authToken=$(get_auth_token)&karteNr=$KARTEN_ID&datumVon=12.02.2018&datumBis=$(date -d tomorrow +%d.%m.%Y)" \ + -H "$authorization_header" \ + | ${pkgs.jq}/bin/jq + } + + get_items() { + ${pkgs.curl}/bin/curl -sSL "$endpoint/TRANSPOS?format=JSON&authToken=$(get_auth_token)&karteNr=$KARTEN_ID&datumVon=12.02.2018&datumBis=$(date -d tomorrow +%d.%m.%Y)" \ + -H "$authorization_header" \ + | ${pkgs.jq}/bin/jq + } + + get_transactions > transactions-$(date -I).json + get_items > items-$(date -I).json + ''; + }; +} diff --git a/secrets b/secrets index aaefa9e..aac75be 160000 --- a/secrets +++ b/secrets @@ -1 +1 @@ -Subproject commit aaefa9ed14fac862ebc6699b3d3ae6c2544dbfbb +Subproject commit aac75be4fd9ab921480a5b26e7d55585ac816586