From 9535123f8c66b8a473621f7aebfb5bb4295e43ca Mon Sep 17 00:00:00 2001 From: Lucie Scarlet Date: Thu, 4 Jul 2024 00:45:32 +0200 Subject: [PATCH] Accounted for uptime script Install now installs the uptime python3 script to /opt and adds the script to crontab --- i3/install.sh | 14 ++++++++++++++ i3/uptime.py | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 i3/uptime.py diff --git a/i3/install.sh b/i3/install.sh index dbf4a81..7c6ea54 100755 --- a/i3/install.sh +++ b/i3/install.sh @@ -1,6 +1,20 @@ #!/bin/bash +echo "Installing i3 config" mkdir -p ~/.config/i3 cp ./i3config ~/.config/i3/config +echo "Installing i3status config" mkdir -p ~/.config/i3status cp ./i3status ~/.config/i3status/config + +echo "Installing uptime script" +sudo -s < /tmp/uptime" | tee -a $ct +echo "@reboot python3 /opt/uptime.py > /tmp/uptime" | tee -a $ct + +crontab $ct diff --git a/i3/uptime.py b/i3/uptime.py new file mode 100644 index 0000000..d263030 --- /dev/null +++ b/i3/uptime.py @@ -0,0 +1,18 @@ +from datetime import timedelta + + +def main() -> int: + raw_uptime: str = "" + with open("/proc/uptime", "r") as uptime: + raw_uptime = uptime.read() + text_uptime: str = raw_uptime.split()[0] + raw_formatted = timedelta(seconds=(float(text_uptime))) + well_formatted: str = str(raw_formatted).split(".")[0][:-3] + fmt = well_formatted.split(".")[0] + hours = fmt.split(":")[0] + mins = fmt.split(":")[1] + print(f"Uptime: {hours}h {mins}m") + + +if __name__ == "__main__": + raise SystemExit(main()) -- 2.45.2