Skip to content

Instantly share code, notes, and snippets.

@wetmore
Last active December 23, 2015 07:29
Show Gist options
  • Save wetmore/6600824 to your computer and use it in GitHub Desktop.
Save wetmore/6600824 to your computer and use it in GitHub Desktop.
hack101 api
import requests
import os
twilio_sid = os.environ['TWILIO_SID']
twilio_auth = os.environ['TWILIO_AUTH']
twilio_url = 'https://api.twilio.com/2010-04-01/Accounts/%(twilio_sid)s/SMS/Messages.json' % locals()
weather_url = 'http://api.openweathermap.org/data/2.5/weather'
weather_params = {'q': 'montreal'}
r = requests.get(weather_url, params=weather_params)
json = r.json()
abs_zero_offset = 273.15
info = {
't_max': json['main']['temp_max'] - abs_zero_offset,
't_min': json['main']['temp_min'] - abs_zero_offset,
'desc' : json['weather'][0]['description']
}
text = 'High of %(t_max)1.2f C, low of %(t_min)1.2f C. %(desc)s.' % info
twilio_data = {
'From': '+15146001014',
'To': '+15145490432',
'Body': text
}
t = requests.post(twilio_url, data=twilio_data, auth=(twilio_sid, twilio_auth))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment