-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuptime.py
32 lines (25 loc) · 837 Bytes
/
uptime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from operator import mod
from qtile_extras import widget
from modules.settings import colors
def get_uptime():
with open("/proc/uptime", "r") as f:
seconds = int(float(f.readline().split()[0]))
days = seconds // 86400
hours = mod(seconds, 86400) // 3600
if days == 0:
return f"up {hours}h"
return f"up {days}d" if hours == 24 else f"up {days}d,{hours}h"
class Uptime(widget.GenPollText):
defaults = [
("update_interval", 3600, "Update interval in seconds"),
("padding", 5, ""),
("fontsize", 13, ""),
("foreground", colors["fg2"], ""),
(
"func",
lambda: str(get_uptime()),
),
]
def __init__(self, **config):
widget.GenPollText.__init__(self, **config)
self.add_defaults(Uptime.defaults)