psutil
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8"""A clone of 'sensors' utility on Linux printing hardware temperatures.
9
10$ python3 scripts/sensors.py
11asus
12asus 47.0 °C (high = None °C, critical = None °C)
13
14acpitz
15acpitz 47.0 °C (high = 103.0 °C, critical = 103.0 °C)
16
17coretemp
18Physical id 0 54.0 °C (high = 100.0 °C, critical = 100.0 °C)
19Core 0 47.0 °C (high = 100.0 °C, critical = 100.0 °C)
20Core 1 48.0 °C (high = 100.0 °C, critical = 100.0 °C)
21Core 2 47.0 °C (high = 100.0 °C, critical = 100.0 °C)
22Core 3 54.0 °C (high = 100.0 °C, critical = 100.0 °C)
23"""
24
25from __future__ import print_function26
27import sys28
29import psutil30
31
32def main():33if not hasattr(psutil, "sensors_temperatures"):34sys.exit("platform not supported")35temps = psutil.sensors_temperatures()36if not temps:37sys.exit("can't read any temperature")38for name, entries in temps.items():39print(name)40for entry in entries:41line = " %-20s %s °C (high = %s °C, critical = %s °C)" % (42entry.label or name,43entry.current,44entry.high,45entry.critical,46)47print(line)48print()49
50
51if __name__ == '__main__':52main()53