diff options
author | Mark Powers <mark@marks.kitchen> | 2021-07-12 20:27:50 -0500 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2021-07-12 20:27:50 -0500 |
commit | 5b2a3f0da147f17f6ab32af8e3d14fb29de71fd1 (patch) | |
tree | 6e025bba1712f7f183fe568e2acc5b1f8e5870d5 /events.py | |
parent | e3f4893b74b97e1de5e126761d9ec6a0f6585888 (diff) |
Fix handler so events cannot be dialed while one is playing, and so events can be terminated
Diffstat (limited to 'events.py')
-rw-r--r-- | events.py | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -4,6 +4,17 @@ from config import config import requests from multiprocessing import Process +class SpeakProcess(Process): + def __init__(self, text): + super().__init__() + self.daemon = True + self.text = text + + def run(self): + print("speaking:", self.text) + subprocess.run(["espeak", self.text]) + + class Event(): def __init__(self, dial_manager, phone_held, phone_hung_up): self.dial_manager = dial_manager @@ -17,9 +28,11 @@ class Event(): return "event" def speak(self): - text = self.get_text() - print("speaking:", text) - subprocess.run(["espeak", text]) + process = subprocess.Popen(["espeak", self.get_text()]) + while process.poll() is None: + if self.phone_hung_up.wait(timeout=0.1): + process.terminate() + class FortuneEvent(Event): def get_name(self): @@ -56,7 +69,12 @@ class OperatorEvent(Event): def get_text(self): now = datetime.now() - return f"Right now, it is {now.hour} {now.minute}. Dial 4 1 1 for directory." + nearest_quarter = ((n.minute // 15 + 1) * 15) % 60 + hour = now.hour % 12 + day_half = "A M" + if hour != now.hour: + day_half = "P M" + return f"Right now, it is {hour} {now.minute} {day_half}." class WeatherEvent(Event): |