-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensorsrt.py
61 lines (53 loc) · 1.92 KB
/
sensorsrt.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
50
51
52
53
54
55
56
57
58
59
60
61
from sys import argv
import os
from colorama import Fore, init
from time import sleep
# initializing colorama
init(autoreset=True)
def clearConsole():
"""
Clears the console display
"""
if os.name == 'posix': # linux and unix-based oses.
os.system("clear")
elif os.name == 'nt': # windows nt
os.system("cls")
else:
print(f"{Fore.RED}error: unsupported os type: {os.name}, will clear console using 'clear'")
os.system("clear")
return None
def printSensorsReading():
print("Sensors available for this PC")
print('', end='\n\n')
print("ISA/PCI Bridges and CPU Temperatures (using lm_sensors):")
os.system("sensors")
print('', end='\n\n')
print("Hard drive temperatures (using hddtemp):")
os.system("hddtemp SATA:/dev/sda")
os.system("hddtemp SATA:/dev/sdb")
print('', end='\n\n')
print(f"{Fore.YELLOW}info: this will return anything but real drive temperatures if your hard drive is unsupported or the module is not installed or if not running as sudo user")
print('', end='\n\n')
return None
if __name__ == '__main__':
try:
if len(argv) == 1:
while True:
clearConsole()
printSensorsReading()
sleep(2) # refresh rate is 2 seconds
elif len(argv) == 2:
try:
refresh_rate_insecs = int(argv[1])
except Exception:
print(f"{Fore.RED}error: couldn't convert '{argv[1]}' to int for use with parameter 'refreshrateinsecs'")
raise SystemExit(10)
while True:
clearConsole()
printSensorsReading()
sleep(refresh_rate_insecs)
else:
print(f"{Fore.RED}error: invalid command line usage, script only accepts 1 argument: refreshrateinsecs")
raise SystemExit(20)
except KeyboardInterrupt:
raise SystemExit(0)