Skip to content

A Twilio application that returns weather data for your area code in exactly 25 lines of code.

License

Notifications You must be signed in to change notification settings

mitani/25-Lines-SMS-Weather

 
 

Repository files navigation

25 Lines - SMS Weather

A Twilio application that returns weather data for your area code in exactly 25 lines of code.

[Build Status] (http://travis-ci.org/RobSpectre/25-Lines-SMS-Weather)

Summary

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.

Usage

Text anything to (646) 606-2458 to see it work!

Example of it working

Installation

Step-by-step on how to deploy, configure and develop this app.

Deploy

  1. Get a developer API key from Weather Underground.

  2. Grab latest source

git clone git://github.com/RobSpectre/25-Lines-SMS-Weather.git 
  1. Install dependencies
make init
  1. Navigate to folder and create new Heroku Cedar app
heroku create --stack cedar
  1. Deploy to Heroku
git push heroku master
  1. Scale your dynos
heroku scale web=1
  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
  1. 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
  1. Text the new number and get the weather!

Configuration

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.

Development

Be sure to follow the configuration steps above and use this step-by-step guide to tweak to your heart's content.

  1. Install the dependencies.
make init
  1. Launch local development webserver
foreman start
  1. Open browser to http://localhost:5000.

  2. Tweak away on app.py.

Testing

Of course its tested. What is this? 1997?

make test

Meta

About

A Twilio application that returns weather data for your area code in exactly 25 lines of code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published