From 6480ee5b9e05a763eef929250bf14acaa8631202 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 20 Apr 2019 19:30:14 +0200 Subject: pkgs/profpatsch/display-infos: add sfttime and AC charger --- pkgs/profpatsch/display-infos/default.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'pkgs/profpatsch/display-infos') diff --git a/pkgs/profpatsch/display-infos/default.nix b/pkgs/profpatsch/display-infos/default.nix index d213241c..9dc510cd 100644 --- a/pkgs/profpatsch/display-infos/default.nix +++ b/pkgs/profpatsch/display-infos/default.nix @@ -1,8 +1,8 @@ -{ lib, runCommand, python3, libnotify }: +{ lib, runCommand, writeText, python3, libnotify, sfttime }: let name = "display-infos-0.1.0"; - script = builtins.toFile (name + "-script") '' + script = writeText (name + "-script") '' #!@python3@ import sys @@ -11,19 +11,22 @@ let import os.path as path import statistics as st + def readint(fn): + with open(fn, 'r') as f: + return int(f.read()) + full = 0 now = 0 for bat in glob.iglob("/sys/class/power_supply/BAT*"): - def readint(fn): - with open(fn, 'r') as f: - return int(f.read()) full += readint(path.join(bat, "energy_full")) now += readint(path.join(bat, "energy_now" )) bat = round( now/full, 2 ) + ac = "🗲" if readint("/sys/class/power_supply/AC/online") else "" date = sub.run(["date", "+%d.%m. %a %T"], stdout=sub.PIPE).stdout.strip().decode() - notify = "BAT: {}% | {}".format(int(bat*100), date) + sfttime = sub.run(["${sfttime}/bin/sfttime"], stdout=sub.PIPE).stdout.strip().decode() + notify = "BAT: {}% {} | {} | {}".format(int(bat*100), ac, date, sfttime) sub.run(["@notify-send@", notify]) ''; -- cgit 1.4.1