These two python scripts will accept a mail message at STDIN and call or text via the Twillio service.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

41 rinda
899B

  1. #!/usr/bin/python3
  2. from twilio.rest import Client
  3. import sys
  4. import email
  5. import re
  6. import unidecode
  7. def slugify(text):
  8. text = unidecode.unidecode(text).lower()
  9. return re.sub(r'\W+', '-', text)
  10. # Find these values at https://twilio.com/user/account
  11. account_sid = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  12. auth_token = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"
  13. client = Client(account_sid, auth_token)
  14. raw_msg = ""
  15. for line in sys.stdin:
  16. raw_msg = raw_msg + line
  17. msg = email.message_from_string(raw_msg)
  18. text = msg['Subject']
  19. if msg.is_multipart():
  20. for payload in msg.get_payload():
  21. text = text + payload.get_payload()
  22. else:
  23. text = text + msg.get_payload()
  24. text = text[:160] if len(text) > 160 else text
  25. text = slugify(text)
  26. call = client.calls.create(
  27. to = "+357XXXXXX",
  28. from_ = "+177XXXXXXXX",
  29. url="http://twimlets.com/message?Message%5B0%5D=" + text + "&",
  30. )