Skip to content

Instantly share code, notes, and snippets.

@nkarnik
Last active August 29, 2015 14:11
Show Gist options
  • Save nkarnik/311d3a9bd851186ee4b3 to your computer and use it in GitHub Desktop.
Save nkarnik/311d3a9bd851186ee4b3 to your computer and use it in GitHub Desktop.
Zillabyte component that uses Twilio to send an SMS to a subscriber about the local weather forecast
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