RandomUsefulStuff/sensors.py

21 lines
519 B
Python
Raw Normal View History

2021-05-01 06:51:35 +02:00
import os, json, sys
try:
sensor_group = sys.argv[1]
sensor = sys.argv[2]
except IndexError:
print("usage: python3 "+sys.argv[0]+" <sensor group> <sensor>")
sys.exit(1)
sensors_process = os.popen("sensors -j")
temps_str = sensors_process.read()
sensors_process.close()
temps = json.loads(temps_str)
try:
print([value for key, value in temps[sensor_group][sensor].items() if key.endswith("input")][0])
except KeyError:
print("Sensor \""+sensor_group+":"+sensor+" not found!")
sys.exit(1)