cfg/.config/i3blocks/temp
Knut Ahlers 36441150a8
Migrate temp to block usage
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-09-12 16:14:28 +02:00

65 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python
import json
import re
import subprocess
from block import *
CRIT = 70.0
CHIP_BLACKLIST = []
SENSOR_BLACKLIST = [r'^AUXTIN[0-9]']
ICON = '\uf2c7'
class Temp(Block):
def in_blacklist(self, identifier, blacklist):
for entry in blacklist:
if entry == identifier or re.match(entry, identifier):
return True
return False
def execute(self):
sensors_data = json.loads(subprocess.check_output(
['sensors', '-j']).decode('utf-8'))
max_temp = 0.0
for chip, sensors in sensors_data.items():
if self.in_blacklist(chip, CHIP_BLACKLIST):
continue
for sensor, readings in sensors.items():
if self.in_blacklist(sensor, SENSOR_BLACKLIST):
continue
if type(readings) == str:
continue
for name, value in readings.items():
if not re.match(r'^temp._input$', name):
continue
if value > max_temp:
max_temp = value
color = '#ffffff'
if max_temp > CRIT:
color = '#dd0000'
return self.color_text(
self.safe_text('{:.1f}°C'.format(max_temp)),
color=color,
)
def main():
block = Temp(ICON)
block.render()
if __name__ == '__main__':
main()