diff options
-rw-r--r-- | events.py | 30 | ||||
-rwxr-xr-x | main.py | 23 |
2 files changed, 43 insertions, 10 deletions
@@ -2,6 +2,7 @@ import subprocess from datetime import datetime from config import config import requests +from multiprocessing import Process class Event(): def __init__(self, dial_manager, phone_held, phone_hung_up): @@ -89,3 +90,32 @@ class TimerEvent(Event): end = datetime.now() print(end - start) return "time" + +class RecordThread(Process): + def __init__(self): + super().__init__() + self.daemon = True + + def run(self): + subprocess.run(["time", "cat"]) + + +class RecordEvent(Event): + def get_name(self): + return "recorder" + + def get_text(self): + start = datetime.now() + print("timer start", start) + + record_thread = RecordThread() + record_thread.start() + + self.phone_hung_up.wait() + print("terminating") + record_thread.terminate() + + end = datetime.now() + print(end - start) + + return str(end-start) @@ -24,15 +24,18 @@ if __name__ == "__main__": hang_up_thread.start() while True: - # Wait for phone to be picked up - phone_held.wait() - # Dial a number try: - dialed = queue.get(block=True, timeout=0.1) - except: - continue - response = dial_manager.dial(dialed) - # If we matched a sequence, play out event - if response is not None: - response.speak() + # Wait for phone to be picked up + phone_held.wait() + # Dial a number + try: + dialed = queue.get(block=True, timeout=0.1) + except: + continue + response = dial_manager.dial(dialed) + # If we matched a sequence, play out event + if response is not None: + response.speak() + except Exception as e: + print(e) |