mirror of
https://github.com/kmein/niveum
synced 2026-03-16 10:11:08 +01:00
feat: stw-berlin stats
This commit is contained in:
@@ -292,6 +292,7 @@ in {
|
||||
./watson.nix
|
||||
./zsh.nix
|
||||
./tor.nix
|
||||
./stw-berlin.nix
|
||||
./mastodon-bot.nix
|
||||
];
|
||||
}
|
||||
|
||||
51
configs/stw-berlin.nix
Normal file
51
configs/stw-berlin.nix
Normal file
@@ -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
|
||||
'';
|
||||
};
|
||||
}
|
||||
2
secrets
2
secrets
Submodule secrets updated: aaefa9ed14...aac75be4fd
Reference in New Issue
Block a user