aboutsummaryrefslogtreecommitdiff
path: root/events.py
diff options
context:
space:
mode:
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."
+