diff options
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): |