forked from eschava/psmqtt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilters.py
40 lines (27 loc) · 824 Bytes
/
filters.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
33
34
35
36
37
38
39
40
def kb(value):
return str(value / 1024) + " KB"
def mb(value):
return str(value / 1024 / 1024) + " MB"
def gb(value):
return str(value / 1024 / 1024 / 1024) + " GB"
def uptime(boot_time):
import time
upt = time.time() - boot_time
retval = ""
days = int(upt / (60 * 60 * 24))
if days != 0:
retval += str(days) + " " + ("days" if days > 1 else "day") + ", "
minutes = int(upt / 60)
hours = int(minutes / 60)
hours %= 24
minutes %= 60
if hours != 0:
retval += str(hours) + ":" + (str(minutes) if minutes >= 10 else "0" + str(minutes))
else:
retval += str(minutes) + " min"
return retval
def register_filters(env):
env.filters['KB'] = kb
env.filters['MB'] = mb
env.filters['GB'] = gb
env.filters['uptime'] = uptime