Add a recipe renderer and trigger.
[kiosk.git] / health_renderer.py
1 #!/usr/bin/env python3
2
3 import logging
4 import subprocess
5 from typing import Dict
6
7 import file_writer
8 import renderer
9
10
11 logger = logging.getLogger(__file__)
12
13
14 class periodic_health_renderer(renderer.abstaining_renderer):
15     def __init__(self, name_to_timeout_dict: Dict[str, int]) -> None:
16         super().__init__(name_to_timeout_dict)
17
18     def periodic_render(self, key: str) -> bool:
19         with file_writer.file_writer("periodic-health_6_300.html") as f:
20             command = "/home/pi/bin/cronhealth.py --kiosk_mode"
21             p = subprocess.Popen(command, shell=True, bufsize=0, stdout=subprocess.PIPE)
22             for line in iter(p.stdout.readline, b''):
23                 f.write(line.decode("utf-8"))
24             p.stdout.close()
25         return True
26
27 #test = periodic_health_renderer({"Test", 123})
28 #test.periodic_render("Test")