63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
# import clr # from pythonnet
|
|
# import os
|
|
# import sys
|
|
|
|
# # Path to the LibreHardwareMonitor DLL
|
|
# dll_path = r"LibreHardwareMonitorLib.dll"
|
|
# sys.path.append(os.path.dirname(dll_path))
|
|
# clr.AddReference("LibreHardwareMonitorLib")
|
|
|
|
# from LibreHardwareMonitor.Hardware import Computer
|
|
|
|
# def get_cpu_temperature():
|
|
# computer = Computer()
|
|
# computer.IsCpuEnabled = True
|
|
# computer.Open()
|
|
|
|
# temperatures = []
|
|
# print(computer.Hardware.CPU)
|
|
# return 80
|
|
|
|
# for hardware in computer.Hardware:
|
|
# if hardware.HardwareType.ToString() == "Cpu":
|
|
# hardware.Update()
|
|
# for sensor in hardware.Sensors:
|
|
# if sensor.SensorType.ToString() == "Temperature":
|
|
# print(f"{sensor.Name}: {sensor.Value} °C")
|
|
# temperatures.append(sensor.Value)
|
|
|
|
# computer.Close()
|
|
# return max(temperatures) if temperatures else None
|
|
|
|
# temp = get_cpu_temperature()
|
|
# if temp:
|
|
# print(f"Highest CPU temperature: {temp} °C")
|
|
# else:
|
|
# print("No CPU temperatures found.")
|
|
from PyLibreHardwareMonitor import Computer
|
|
|
|
|
|
# Get system information, automatically refreshed with each call.
|
|
def get_cpu_data( ):
|
|
computer = Computer()
|
|
|
|
cpu_temps = { }
|
|
cpu_usage = { }
|
|
cpu_combined = { }
|
|
|
|
for mobo in computer.motherboard:
|
|
print(computer.motherboard[mobo])
|
|
|
|
for cpu in computer.cpu:
|
|
#print(computer.cpu[cpu])
|
|
for core in computer.cpu[cpu]['Load']:
|
|
#print(core)
|
|
if core.find("CPU Core #") != -1 and len(core) <= len("CPU Core #10"):
|
|
cpu_combined[core] = {'load' : computer.cpu[cpu]['Load'][core]}
|
|
for core in computer.cpu[cpu]['Temperature']:
|
|
#print(core, computer.cpu[cpu]['Temperature'][core])
|
|
if core.find("CPU Core #") != -1 and len(core) <= len("CPU Core #10"):
|
|
cpu_combined[core]['temp'] = computer.cpu[cpu]['Temperature'][core]
|
|
return cpu_combined #{'Temperatures' : cpu_temps, 'Loads' : cpu_usage}
|
|
|
|
print(get_cpu_data( )) |