A Twilio application that returns weather data for your area code in exactly 25 lines of code.
[] (http://travis-ci.org/RobSpectre/25-Lines-SMS-Weather)
On a flight from LAX to SFO, I issued myself the challenge to build a compelling Twilio app in 25 lines or less over the course of the 50 minute flight. The rules I set for myself were:
- It had to do something significant. Couldn't be something silly like Laughotron.
- Start to finish in no more than 25 lines, including whitespace.
- It had to pass my PEP8 vim plugin. No crazy single-line, more than 80 column shenanigans.
- Application had to be code complete by the time the Delta attendant started to scream at me for still operating an electronic device.
- It must withstand a reasonable amount of poor user input - no brittleware.
To accomplish this, I busted out the Twilio Hackpack for Heroku and Flask and the Weather Underground API to make a super simple SMS weather reporter.
Text anything to (646) 606-2458 to see it work!
Step-by-step on how to deploy, configure and develop this app.
-
Get a developer API key from Weather Underground.
-
Grab latest source
git clone git://github.com/RobSpectre/25-Lines-SMS-Weather.git
- Install dependencies
make init
- Navigate to folder and create new Heroku Cedar app
heroku create --stack cedar
- Deploy to Heroku
git push heroku master
- Scale your dynos
heroku scale web=1
- Configure a new TwiML app and Twilio phone number to use the app.
python configure.py --account_sid ACxxxxxx --auth_token yyyyyyy -n -N
- Set your Weather Underground API key in your local and Heroku app environment variables.
export WUNDERGROUND_API_KEY=xxxxxxxxxx heroku config:add WUNDERGROUND_API_KEY=xxxxxxxxxx
- Text the new number and get the weather!
This app hinges on your Weather Underground API key being set in your environment. This can be hardcoded into your app by changing the first string substitution on line 14:
path = "http://api.wunderground.com/api/%s/conditions/q/%s.json" \
% ("xxxxxxxxxxx", flask.request.form['FromZip'])
Be sure not to expose your key (or any of your sensitive credentials) to a public GitHub repo.
Be sure to follow the configuration steps above and use this step-by-step guide to tweak to your heart's content.
- Install the dependencies.
make init
- Launch local development webserver
foreman start
-
Open browser to http://localhost:5000.
-
Tweak away on
app.py
.
Of course its tested. What is this? 1997?
make test
- No warranty expressed or implied. Software is as is. Diggity.
- MIT License
- Lovingly crafted by Twilio New York