diff options
Diffstat (limited to 'events.py')
-rw-r--r-- | events.py | 34 |
1 files changed, 27 insertions, 7 deletions
@@ -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]]) |