-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTemperature.py
35 lines (29 loc) · 1.19 KB
/
Temperature.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
import re
import random
import json
from subprocess import Popen, PIPE
WORDS = ["DEGREES"]
def handle(text, mic, profile):
temperature_as_string = "42"
p = Popen(["python3", "/home/pi/jasper-client/client/modules/client.py"], stdout=PIPE, bufsize=1)
with p.stdout:
for line in iter(p.stdout.readline, b''):
temperature_as_string = str(line)[3:-3]
print "Step 1, check"
print 'Temperature_as_string: ' + temperature_as_string
#p.wait() # wait for the subprocess to exit
#temperature_as_string = client.client()
#regex = r'.*(\d*).*'
#matches = re.match(regex, str(temperature_as_string))
#resultnumber = matches.group(0)
#resultstring = '{"temperature": ' + str(resultnumber) + '}'
#print resultstring
print "loading json"
temperature_as_json = json.loads(temperature_as_string)
print "json loaded"
temperature_as_int = temperature_as_json["temperature"]
temperature_rounded = round((temperature_as_int/100.0), 2)
print temperature_rounded
mic.say("This room has a Temperature of %s degrees" % temperature_rounded)
def isValid(text):
return bool(re.search(r'\bdegrees\b', text, re.IGNORECASE))