Files
dotfiles/system-modules/health_reminder.nix
Lennart J. Kurzweg (Nx2) a0911caacf better scripts
2024-06-27 12:34:49 +02:00

68 lines
2.3 KiB
Nix
Executable File

{ config, pkgs, lib, host, ... }:
lib.mkIf (host != "NxACE")
{
systemd.timers."health_reminder" = {
enable = true;
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5m";
OnUnitActiveSec = "5m";
Unit = "health_reminder.service";
};
};
systemd.services."health_reminder" =
let
hm =
let p = /*python*/ ''
#!${pkgs.python3}/bin/python3
import random
import re
class Action:
def __init__(self, action: str, likelihood: int, options: list[str] = None):
self.action = action
self.likelihood = likelihood
self.options = options if options is not None else []
def __str__(self):
try:
choice = random.choice(self.options)
except IndexError:
choice = ""
action = re.sub("%o", choice, self.action)
return action
actions = [
Action("look away for %o Seconds!",300, ["10", "15"] ),
Action("Posture Check!", 90 ),
Action("Do %o Biceps curls!", 5, ["50", "100", "150"] ),
Action("Do %o Shourlder thingees", 5, ["40 + 40", "50", "60"]),
Action("Plank for %o senonds!", 5, ["60", "60", "70"] ),
Action("Strech your upper body!", 20 ),
Action("Strech your core!", 10 ),
Action("Strech your legs!", 10 ),
Action("Make Tea!", 5 ),
Action("Touch Grass!", 5 )
]
total_likelihood = sum(a.likelihood for a in actions)
random_action = random.choices(actions, [a.likelihood for a in actions], k=1)[0]
print(random_action)
'';
in pkgs.writeScriptBin "health_reminder" p;
in
{
script = ''
set -eu
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"
${pkgs.libnotify}/bin/notify-send "$(${hm}/bin/health_reminder)"
'';
serviceConfig = {
Type = "oneshot";
User = "nx2";
};
};
}