1212vfd = VFD (0 , 0 )
1313welcome = "PiHole Monitor"
1414HOST = str (socket .gethostbyname (socket .gethostname ()))
15- URL = ("http://" + HOST + "/admin/api.php" )
15+ URL = "http://" + HOST + "/admin/api.php"
16+
1617
1718def 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+
2831def 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
3943def 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+
8287if __name__ == "__main__" :
8388 main ()
0 commit comments