Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Zillabyte app that queries weather forecasts from a list of cities and sends an SMS with Twilio to local subscribers when it is expected to rain
import zillabyte
twilio_sid = "SID_HERE"
twilio_auth = "AUTH_HERE"
class TwilioEach:
def prepare(self, controller):
# Dictionary of phone numbers subscribed to cities (just for show with small sample, please use a
# REAL source when using a significant number of phone numbers)
self.text_to = {"Baltimore" : ["301-814-1234", "443-484-2310"], "San Francisco" : ["415-687-9087"]}
self.text_from = ["+12408396196"]
def execute(self, controller, tup):
#only send text if raining
if tup["condition"] == "raining":
#iterate through array of phone numbers subscribed to current city, and emit all info
for number in text_to[current_city]:
controller.emit({"twilio_sid" : twilio_sid,"twilio_auth" : twilio_auth, "text_to" : self.text_to,
"text_from" : self.text_from, "condition" : tup["condition"], "city" : tup["city"]})
app = zillabyte.app(name="zillaweather")
#source from list of world cities
stream = app.source("all_cities")
#call component to find current weather condition at each city
stream = stream.call_component("current_weather")
#Use current weather and dictionary of cities : numbers to send a SMS with Twilio
stream = stream.each(TwilioEach, name="Prepare_Twilio")
stream = stream.call_component("twilio_weather_text")
stream.sink(name="weather", columns = [{"to":"string"}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment