1
0
Fork 0
twillio_alerts/call_alerts.py

41 Zeilen
899 B
Python
Ausführbare Datei

#!/usr/bin/python3
from twilio.rest import Client
import sys
import email
import re
import unidecode
def slugify(text):
text = unidecode.unidecode(text).lower()
return re.sub(r'\W+', '-', text)
# Find these values at https://twilio.com/user/account
account_sid = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"
client = Client(account_sid, auth_token)
raw_msg = ""
for line in sys.stdin:
raw_msg = raw_msg + line
msg = email.message_from_string(raw_msg)
text = msg['Subject']
if msg.is_multipart():
for payload in msg.get_payload():
text = text + payload.get_payload()
else:
text = text + msg.get_payload()
text = text[:160] if len(text) > 160 else text
text = slugify(text)
call = client.calls.create(
to = "+357XXXXXX",
from_ = "+177XXXXXXXX",
url="http://twimlets.com/message?Message%5B0%5D=" + text + "&",
)