What we did on 3/10/15

Posted by Zev Averbach on March 10, 2015

Using Twilio’s quickstart for Python, we successfully sent ourselves “hello world” text messages.

Then we looked around for a good weather forecast API, thinking we’d text ourselves, “You need an umbrella,” if the chance of rain was significant. Findings about that:

  • Weather Underground sends you in an infinite loop if you try to sign up and log into their API page.
  • OpenWeatherMap doesn’t actually do forecasting – oops.
  • The Dark Sky Forecast API == winner

This got us the current chance of precipitation:

api_key = "our_forecastio_api_key"
# Burlington VT latitude and longitude:
lat = 44.48 
lng = -73.21
forecast = forecastio.load_forecast(api_key, lat, lng)
precip_prob = forecast.currently().precipProbability

And this texted us one way or the other:

from twilio.rest import TwilioRestClient


def send_umbrella(message):
	account_sid = ""
	auth_token = ""
	client = TwilioRestClient(account_sid, auth_token)
	client.messages.create(to="", from_="", body=message)

	if precip_prob > .3:
		send_umbrella("Bring your umbrella!")
	else:
		send_umbrella("Don't bother with the umbrella.")

Next week we’ll start delving into chapters 1-6 of Real Python book two: Flask and databases.