-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobe.py
40 lines (30 loc) · 1.07 KB
/
probe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import logging
import re
from config import probes_paths
logger = logging.getLogger("probe")
pattern = r"t=(\d+|-\d+|)"
def parse_temperature_as_int(probe_file_content):
match = re.search(pattern, probe_file_content)
if match:
print("Found in file :", str(match.group(1)))
extracted_number = int(match.group(1))
print("Converted :", int(match.group(1)))
return extracted_number
else:
raise ValueError("Temperature not found in file")
class Probe(object):
def __init__(self, file_path):
self.__path = file_path
# We test if the file exists
with open(self.__path) as probe_temp_file:
probe_temp_file.read()
def get_temperature(self):
with open(self.__path) as probe_temp_file:
file_content = probe_temp_file.read()
return parse_temperature_as_int(file_content)
probes = {}
for i in range(len(probes_paths)):
try:
probes[i + 1] = Probe(probes_paths[i])
except FileNotFoundError:
logger.info(f"Probe {i + 1} not found (path: {probes_paths[i]})")