aboutsummaryrefslogtreecommitdiff
path: root/events.py
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2021-07-12 02:00:54 +0100
committerMark Powers <mark@marks.kitchen>2021-07-12 02:00:54 +0100
commit1edb32ec29ca3c1bf4d1a53215ecb2544aa04a6e (patch)
treed770c0f3dd74dab11a5b13c54f37b14c81daa990 /events.py
parenta981a50b0597498a9fc92249f93f940998455ca3 (diff)
Refactor code to support phone hangup button
Diffstat (limited to 'events.py')
-rw-r--r--events.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/events.py b/events.py
new file mode 100644
index 0000000..77480b9
--- /dev/null
+++ b/events.py
@@ -0,0 +1,64 @@
+import subprocess
+from datetime import datetime
+
+class Event():
+ def __init__(self, dial_manager):
+ self.dial_manager = dial_manager
+
+ def get_name(self):
+ return "generic event"
+
+ def get_text(self):
+ return "event"
+
+ def speak(self):
+ text = self.get_text()
+ print("speaking:", text)
+ subprocess.run(["espeak", text])
+
+class FortuneEvent(Event):
+ def __init__(self, dial_manager):
+ super().__init__(dial_manager)
+
+ def get_name(self):
+ return "fortune"
+
+ def get_text(self):
+ res = subprocess.run(["fortune", "-s"], stdout=subprocess.PIPE)
+ return res.stdout.decode("utf-8")
+
+class DirectoryEvent(Event):
+ def __init__(self, dial_manager):
+ super().__init__(dial_manager)
+
+ def get_name(self):
+ return "directory"
+
+ def get_text(self):
+ def recursive_build(prefix, sequences):
+ sequence_list = []
+ for key in sequences.keys():
+ sequence = prefix+" "+str(key)
+ if isinstance(sequences[key], dict):
+ sequence_list += recursive_build(sequence, sequences[key])
+ else:
+ sequence_list.append((sequence, sequences[key]))
+ return sequence_list
+ sequences = self.dial_manager.sequences
+ text = ""
+ for sequence, event in recursive_build("", sequences):
+ text += f"Dial {sequence} for {event.get_name()}. "
+ return text
+
+
+class OperatorEvent(Event):
+ def __init__(self, dial_manager):
+ super().__init__(dial_manager)
+
+ def get_name(self):
+ return "operator"
+
+ def get_text(self):
+ now = datetime.now()
+ return f"Right now, it is {now.hour} {now.minute}. Dial 4 1 1 for directory."
+