Skip to content

Instantly share code, notes, and snippets.

@mickstevens
Forked from nkarnik/twilio_weather_text.py
Last active August 29, 2015 14:15
Show Gist options
  • Save mickstevens/2b57d5c6a8787fa49de5 to your computer and use it in GitHub Desktop.
Save mickstevens/2b57d5c6a8787fa49de5 to your computer and use it in GitHub Desktop.
import zillabyte
from twilio.rest import TwilioRestClient
def send_text(controller, tup):
# Register twilio client
twilio_client = TwilioRestClient(tup["twilio_sid"], tup["twilio_auth"])
try:
# Send message to recipient and wait 1 second (twilio SMS rate limit)
text_body = "It is going to be " + tup['condition'] + " in " + tup['city'] + " tomorrow!"
twilio_client.messages.create(to=tup["to"], from= tup["from"], body= text_body)
# Emit the recipient back to the stream...
controller.emit({"to" : text_to})
time.sleep(1)
except:
pass
component = zillabyte.component(name="twilio_weather_text")
stream = component.inputs(
name = "input_stream",\
fields = [{"twilio_sid" : "string"}, {"twilio_auth" : "string"},\
{"from" : "string"}, {"to" : "string"}, {"city" : "string"},\
{"condition" : "string"}]\
)
stream = stream.each(send_text)
stream.outputs(name = "output_stream", fields=[{"to" : "string"}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment