aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--events.py30
-rwxr-xr-xmain.py23
2 files changed, 43 insertions, 10 deletions
diff --git a/events.py b/events.py
index 1ed185c..cbd17ea 100644
--- a/events.py
+++ b/events.py
@@ -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)
diff --git a/main.py b/main.py
index 674e644..db8b983 100755
--- a/main.py
+++ b/main.py
@@ -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)