diff options
-rw-r--r-- | dial.py | 2 | ||||
-rw-r--r-- | events.py | 34 | ||||
-rwxr-xr-x | main.py | 1 |
3 files changed, 28 insertions, 9 deletions
@@ -55,7 +55,6 @@ class DialManager: self.phone = phone self.update = datetime.now() self._load_sequences() - print(self.sequences) def _load_sequences(self): def recursive_add(classname, sequence_list, sequences, args): @@ -71,6 +70,7 @@ class DialManager: parts = config["sequences"][sequence].split(" ", 1) classname = parts[0] args = parts[1:] + print(sequence, classname, args, sep="\t") recursive_add(classname, list(sequence), self.sequences, args) def dial(self, number): @@ -1,8 +1,13 @@ import subprocess +import requests +import smtplib + +from config import config +from email.message import EmailMessage from datetime import datetime from config import config -import requests from multiprocessing import Process +from os.path import basename def tts_command(text): if config["engine"]["tts"] == "espeak": @@ -101,23 +106,38 @@ class RecordEvent(Event): def run(self): self.phone.run_until_hangup(tts_command("Please record a message.")) - - process = subprocess.Popen(["arecord", "/tmp/out.wav"]) + process = subprocess.Popen(["arecord", config["engine"]["filename"]]) self.phone.wait_until_hung_up() process.terminate() - return "recording done" - + self._send_recording() + return "" + + def _send_recording(self): + msg = EmailMessage() + msg["Subject"] = "Phone Recording" + msg["From"] = config["email"]["user"] + msg["To"] = config["email"]["user"] + msg.set_content("Attached is your message.") + with open(config["engine"]["filename"], 'rb') as f: + data = f.read() + msg.add_attachment(data, maintype="audio", subtype="wav", filename="recording.wav") + + s = smtplib.SMTP(config["email"]["server"], int(config["email"]["port"])) + s.starttls() + s.login(config["email"]["user"], config["email"]["pass"]) + s.send_message(msg) + s.quit() class PlayEvent(Event): def get_name(self): return "play" def run(self): - self.phone.run_until_hangup(["aplay", "/tmp/out.wav"]) + self.phone.run_until_hangup(["aplay", config["engine"]["filename"]]) class WavEvent(Event): def get_name(self): - return self.args[0] + return basename(self.args[0]) def run(self): self.phone.run_until_hangup(["aplay", self.args[0]]) @@ -13,6 +13,5 @@ if __name__ == "__main__": phone.process_dial() except Exception as e: print(e) - raise e finally: phone.clear_event() |