-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
49 lines (39 loc) · 1.33 KB
/
example.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
41
42
43
44
45
46
47
48
49
### Author: Utsav Krishnan (ketankr9@gmail.com) ###
### Bare minimum script ###
# from panel_indicator import PanelIndicator
#
# class MyIndicator(PanelIndicator):
# def __init__(self, update_interval):
# PanelIndicator.__init__(self, update_interval)
#
# # runs after every 1 seconds
# def set_new_value(self):
# return "yayy"
#
# MyIndicator(1)
### Script for showing internet speed ###
from panel_indicator import PanelIndicator
import subprocess
class MyIndicator(PanelIndicator):
""" abstract function(set_new_value) returns a string """
""" update_interval in seconds """
def __init__(self, update_interval):
self.current_val = 0
PanelIndicator.__init__(self, update_interval)
def set_new_value(self):
out, err = self.bash_script_runner("/home/ketankr9/bin/netusage.sh")
old_val = self.current_val
self.current_val = int(out.strip().decode('utf-8'))
# convert bytes to megabytes
val = (self.current_val*1.0 - old_val)/10**3
val /= self.update_interval
if val/10**3 >= 1.0:
# convert megabytes to gigabytes
val /= 10**3
val = round(val, 1)
val = str(val) + " MB"
else:
val = round(val, 1)
val = str(val) + " KB"
return val
MyIndicator(1.5)