diff --git a/sysFanTemp.py b/sysFanTemp.py old mode 100755 new mode 100644 index 432a598..9a44be6 --- a/sysFanTemp.py +++ b/sysFanTemp.py @@ -1,51 +1,104 @@ -#!/usr/bin/python3 import hddtemp import cpufantemp -from rich import print -from rich.layout import Layout -from rich.panel import Panel +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() - layout = Layout() - layout.split_row( - Layout(name="left"), - Layout(name="center"), - Layout(name="right"), - ) - - ## Fan speed on left - fanSpeedString = "" - for fanKey in sorted(fanTempDict["fan"].keys()): - fanSpeed = fanTempDict["fan"][fanKey] - fanSpeedString += f"{fanKey}: {fanSpeed:<4} RPM\n" - p = Panel(fanSpeedString, title="Fan Speed") - p.height = 15 - layout["left"].update(p) - - ## CPU temp on center - cpuTempString = "" - for cpuKey in sorted(fanTempDict["cpu"].keys()): - cpuTemp = fanTempDict["cpu"][cpuKey] - cpuTempString += f"{cpuKey:<8}: {cpuTemp}°C\n" - p = Panel(cpuTempString, title="CPU Temperature") - p.height = 15 - layout["center"].update(p) - - ## HDD temp on right - hddTempString = "" - print(hddtempDict) - for hddname in sorted(hddtempDict.keys()): - temp = hddtempDict[hddname].get("temp", -999.9) - hddTempString += f"{hddname}: {temp}°C\n" - p = Panel(hddTempString, title="HDD Temperature") - p.height = 15 - layout["right"].update(p) - print(layout) - + console = Console() + columns = Columns([ + buildTable_HddTemperature(), + buildTable_CpuTemperature(), + buildTable_FanSpeed() + ], padding=1, expand=True) + console.print(columns) if __name__ == "__main__": main()