Skip to content

Commit d0c42ec

Browse files
committed
Black formatting
1 parent f575d88 commit d0c42ec

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

clock.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010
vfd = VFD(0, 0)
1111
welcome = "Starting Clock"
1212

13+
1314
def clock():
1415
""" Get the time """
1516
now = datetime.datetime.now()
1617
return now.strftime("%H:%M:%S")
1718

19+
1820
def cpu_state() -> str:
1921
""" Get CPU data """
20-
cpu_temp = psutil.sensors_temperatures()['cpu-thermal'][0].current
21-
return f'{int(psutil.cpu_freq().current)} MHz {cpu_temp:.1f} C'
22+
cpu_temp = psutil.sensors_temperatures()["cpu-thermal"][0].current
23+
return f"{int(psutil.cpu_freq().current)} MHz {cpu_temp:.1f} C"
24+
2225

2326
def main():
2427

@@ -42,5 +45,6 @@ def main():
4245
finally:
4346
vfd.clear()
4447

48+
4549
if __name__ == "__main__":
4650
main()

pihole_monitor.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,64 @@
1212
vfd = VFD(0, 0)
1313
welcome = "PiHole Monitor"
1414
HOST = str(socket.gethostbyname(socket.gethostname()))
15-
URL = ("http://" + HOST + "/admin/api.php")
15+
URL = "http://" + HOST + "/admin/api.php"
16+
1617

1718
def cpu_state() -> str:
1819
""" Get CPU data """
19-
cpu_temp = psutil.sensors_temperatures()['cpu-thermal'][0].current
20-
return f'{int(psutil.cpu_freq().current)} MHz {cpu_temp:.1f} C'
20+
cpu_temp = psutil.sensors_temperatures()["cpu-thermal"][0].current
21+
return f"{int(psutil.cpu_freq().current)} MHz {cpu_temp:.1f} C"
22+
2123

22-
def get_bytes(t, iface='eth0') -> int:
24+
def get_bytes(t, iface="eth0") -> int:
2325
""" Get raw network speed """
24-
with open('/sys/class/net/' + iface + '/statistics/' + t + '_bytes', 'r') as f:
26+
with open("/sys/class/net/" + iface + "/statistics/" + t + "_bytes", "r") as f:
2527
data = f.read()
2628
return int(data)
2729

30+
2831
def net_speed() -> str:
2932
""" Calculate live network speed and provide readable value """
30-
tx1 = get_bytes('tx')
31-
rx1 = get_bytes('rx')
33+
tx1 = get_bytes("tx")
34+
rx1 = get_bytes("rx")
3235
sleep(1)
33-
tx2 = get_bytes('tx')
34-
rx2 = get_bytes('rx')
36+
tx2 = get_bytes("tx")
37+
rx2 = get_bytes("rx")
3538
tx_speed = (tx2 - tx1) / 1000000.0
3639
rx_speed = (rx2 - rx1) / 1000000.0
37-
return f'TX:{tx_speed:.3f} RX:{rx_speed:.3f}'
40+
return f"TX:{tx_speed:.3f} RX:{rx_speed:.3f}"
41+
3842

3943
def main():
4044

4145
vfd.home()
4246
vfd.text(welcome.center(COLS))
4347
vfd.setCursor(0, 1)
44-
vfd.text('IP:' + HOST)
48+
vfd.text("IP:" + HOST)
4549
sleep(3)
4650
try:
4751
while True:
4852
data = json.load(urlopen(URL))
49-
blocked = data['ads_blocked_today']
50-
percent = data['ads_percentage_today']
51-
queries = data['dns_queries_today']
52-
domains = data['domains_being_blocked']
53+
blocked = data["ads_blocked_today"]
54+
percent = data["ads_percentage_today"]
55+
queries = data["dns_queries_today"]
56+
domains = data["domains_being_blocked"]
5357
print("Blocked" + str(blocked) + "," + "Percent" + str(percent))
5458
vfd.home()
5559
vfd.text(cpu_state().center(COLS))
5660
vfd.setCursor(0, 1)
57-
vfd.text('Blocked: ' + str(blocked))
61+
vfd.text("Blocked: " + str(blocked))
5862
vfd.setCursor(0, 2)
59-
vfd.text('Percent: ' + str(percent) + "%")
63+
vfd.text("Percent: " + str(percent) + "%")
6064
vfd.setCursor(0, 3)
6165
vfd.text(net_speed().center(COLS))
6266
sleep(4)
6367
vfd.home()
6468
vfd.text(cpu_state().center(COLS))
6569
vfd.setCursor(0, 1)
66-
vfd.text('Queries: ' + str(queries))
70+
vfd.text("Queries: " + str(queries))
6771
vfd.setCursor(0, 2)
68-
vfd.text('Domains: ' + str(domains))
72+
vfd.text("Domains: " + str(domains))
6973
vfd.setCursor(0, 3)
7074
vfd.text(net_speed().center(COLS))
7175
sleep(4)
@@ -79,5 +83,6 @@ def main():
7983
finally:
8084
vfd.clear()
8185

86+
8287
if __name__ == "__main__":
8388
main()

vfd.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from time import sleep
32

43
import spidev
@@ -92,16 +91,16 @@ def setCursor(self, col, row):
9291
_numlines = ROWS
9392
row_offsets = [0x00, 0x40, 0x14, 0x54]
9493
if row > _numlines:
95-
row = _numlines-1
96-
self.command(VFD_SETDDRAMADDR | (col + row_offsets[row]) )
94+
row = _numlines - 1
95+
self.command(VFD_SETDDRAMADDR | (col + row_offsets[row]))
9796
sleep(VFD_SLEEPTIME)
9897

9998
def display(self, _displaycontrol):
100-
_displaycontrol |= self.VFD_DISPLAYON
99+
_displaycontrol |= self.VFD_DISPLAYON
101100
self.command(VFD_DISPLAYCONTROL | _displaycontrol)
102101

103102
def blink_on(self):
104-
_displaycontrol = VFD_DISPLAYON | VFD_CURSORON | VFD_BLINKON
103+
_displaycontrol = VFD_DISPLAYON | VFD_CURSORON | VFD_BLINKON
105104
self.display(_displaycontrol)
106105

107106
def blink_off(self):

0 commit comments

Comments
 (0)