From 6fd0dbd19d19cacb6ccecf01c8bc5b6c3f94d016 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Mon, 13 Apr 2020 09:29:16 +0200 Subject: [PATCH] [modules] re-enable uptime --- modules/contrib/uptime.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 modules/contrib/uptime.py diff --git a/modules/contrib/uptime.py b/modules/contrib/uptime.py new file mode 100644 index 0000000..34e4085 --- /dev/null +++ b/modules/contrib/uptime.py @@ -0,0 +1,30 @@ +# pylint: disable=C0111,R0903 + +"""Displays the system uptime.""" + +# Use absolute_import because there's already a datatime module +# in the same directory +from __future__ import absolute_import + +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +from datetime import timedelta + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text=self.output) + ) + self._uptime = "" + + def output(self, _): + return "{}".format(self._uptime) + + def update(self, widgets): + with open('/proc/uptime', 'r') as f: + uptime_seconds = int(float(f.readline().split()[0])) + self._uptime = timedelta(seconds = uptime_seconds) + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4