TimeWrapper
This commit is contained in:
parent
84ecfc46a0
commit
e2cb6b8d49
@ -1,12 +1,12 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from i3pystatus import IntervalModule
|
from i3pystatus import IntervalModule, formatp
|
||||||
|
from i3pystatus.core.util import TimeWrapper
|
||||||
|
|
||||||
class Uptime(IntervalModule):
|
class Uptime(IntervalModule):
|
||||||
"""
|
"""
|
||||||
Outputs Uptime
|
Outputs Uptime
|
||||||
It's possible to include hours, minutes and seconds as: {h},{m} and {s}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
@ -18,7 +18,7 @@ class Uptime(IntervalModule):
|
|||||||
)
|
)
|
||||||
|
|
||||||
file = "/proc/uptime"
|
file = "/proc/uptime"
|
||||||
format = "up {h} hours {m} min"
|
format = "up {uptime}"
|
||||||
color = "#ffffff"
|
color = "#ffffff"
|
||||||
alert = False
|
alert = False
|
||||||
seconds_alert = 3600
|
seconds_alert = 3600
|
||||||
@ -26,15 +26,15 @@ class Uptime(IntervalModule):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
with open(self.file,'r') as f:
|
with open(self.file,'r') as f:
|
||||||
data = f.read().split()[0]
|
seconds = float(f.read().split()[0])
|
||||||
seconds = float(data)
|
fdict = {
|
||||||
m, s = divmod(int(seconds), 60)
|
"uptime" : TimeWrapper(seconds, "%h:%m"),
|
||||||
h, m = divmod(int(m), 60)
|
}
|
||||||
|
|
||||||
if self.alert:
|
if self.alert:
|
||||||
if seconds > self.seconds_alert:
|
if seconds > self.seconds_alert:
|
||||||
self.color = self.color_alert
|
self.color = self.color_alert
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": self.format.format(h=h,m=m,s=s),
|
"full_text": formatp(self.format, **fdict),
|
||||||
"color": self.color
|
"color": self.color
|
||||||
}
|
}
|
||||||
|
40
uptime.py
40
uptime.py
@ -1,40 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from i3pystatus import IntervalModule, formatp
|
|
||||||
from i3pystatus.core.util import TimeWrapper
|
|
||||||
|
|
||||||
class Uptime(IntervalModule):
|
|
||||||
"""
|
|
||||||
Outputs Uptime
|
|
||||||
"""
|
|
||||||
|
|
||||||
settings = (
|
|
||||||
("format","Format string"),
|
|
||||||
("color","String color"),
|
|
||||||
("alert","If you want the string to change color"),
|
|
||||||
("seconds_alert","How many seconds necessary to start the alert"),
|
|
||||||
("color_alert","Alert color"),
|
|
||||||
)
|
|
||||||
|
|
||||||
file = "/proc/uptime"
|
|
||||||
format = "up {uptime}"
|
|
||||||
color = "#ffffff"
|
|
||||||
alert = False
|
|
||||||
seconds_alert = 3600
|
|
||||||
color_alert = "#ff0000"
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
with open(self.file,'r') as f:
|
|
||||||
seconds = float(f.read().split()[0])
|
|
||||||
fdict = {
|
|
||||||
"uptime" : TimeWrapper(seconds, "%h:%m"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.alert:
|
|
||||||
if seconds > self.seconds_alert:
|
|
||||||
self.color = self.color_alert
|
|
||||||
self.output = {
|
|
||||||
"full_text": formatp(self.format, **fdict),
|
|
||||||
"color": self.color
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user