Skip to content

Instantly share code, notes, and snippets.

@defufna
Created November 23, 2020 14:13
Show Gist options
  • Save defufna/89d56469db6ecb902dcf20187b92e1ca to your computer and use it in GitHub Desktop.
Save defufna/89d56469db6ecb902dcf20187b92e1ca to your computer and use it in GitHub Desktop.
import asciichartpy
import colorama
import subprocess
import time
import re
r = re.compile("(\d+\.?\d*)")
def get_temp():
return next(float(r.findall(line)[1]) for line in subprocess.run("sensors", capture_output=True)
.stdout.decode().splitlines() if "Package id 0" in line)
def get_size():
return reversed([int(v) for v in subprocess.run("stty size", capture_output=True, shell=True).stdout.decode().split()])
def move (y, x):
print("\033[%d;%dH" % (y, x))
def clear():
print("\033[H\033[J")
def main():
colorama.init()
values = []
while True:
temp = get_temp()
values.append(temp)
w, h = get_size()
w = w-10
if len(values) > w:
values = values[len(values)-w:]
clear()
move(0,0)
print(asciichartpy.plot(values, {"height":h-4}))
time.sleep(1)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment