Files
linux_script/sysFanTemp.py
2024-03-27 10:42:46 +00:00

105 lines
2.5 KiB
Python

import hddtemp
import cpufantemp
from rich.console import Console
from rich.columns import Columns
from rich.table import Table
hddtempDict = {}
fanTempDict = {}
def buildTable(title, headers, rows):
table = Table(title=title)
for header in headers:
table.add_column(
header.get("name", "name"),
justify=header.get("justify", "center"),
style=header.get("style", "cyan"),
no_wrap=header.get("no_wrap", False))
for row in rows:
table.add_row(*row)
return table
def buildTable_HddTemperature():
table = buildTable(
"HDD temperature",
[
{
"name": "HDD ID",
"justify": "center",
"style": "cyan",
"no_wrap": True
},
{
"name": "Celuis",
"justify": "center",
"style": "magenta",
},
],
[[f"{hddKey}", f"{hddtempDict[hddKey].get('temp', -999.9)}°C"] for hddKey in hddtempDict.keys()]
)
return table
def buildTable_CpuTemperature():
table = buildTable(
"CPU temperature",
[
{
"name": "CPU ID",
"justify": "center",
"style": "cyan",
"no_wrap": True
},
{
"name": "Celuis",
"justify": "center",
"style": "magenta",
},
],
[[f"{cpuKey}", f"{fanTempDict['cpu'][cpuKey]}°C"] for cpuKey in fanTempDict["cpu"].keys()]
)
return table
def buildTable_FanSpeed():
table = buildTable(
"Fan Speed",
[
{
"name": "Fan ID",
"justify": "center",
"style": "cyan",
"no_wrap": True
},
{
"name": "RPM",
"justify": "center",
"style": "magenta",
},
],
[[f"{fanKey}", f"{fanTempDict['fan'][fanKey]}"] for fanKey in fanTempDict["fan"].keys()]
)
return table
def main():
global hddtempDict
global fanTempDict
hddtempDict = hddtemp.getHddTemp()
fanTempDict = cpufantemp.getCpuTempAndFanSpeed()
console = Console()
columns = Columns([
buildTable_HddTemperature(),
buildTable_CpuTemperature(),
buildTable_FanSpeed()
], padding=1, expand=True)
console.print(columns)
if __name__ == "__main__":
main()