weather "Returns the weather"
GET POST PUT DELETE /weather? Test
import urllib import datetime from xml.dom import minidom WEATHER_URL = 'http://xml.weather.yahoo.com/forecastrss?p=%s' WEATHER_NS = 'http://xml.weather.yahoo.com/ns/rss/1.0' def weather_for_zip(zip_code): url = WEATHER_URL % zip_code dom = minidom.parse(urllib.urlopen(url)) forecasts = [] for node in dom.getElementsByTagNameNS(WEATHER_NS, 'forecast'): forecasts.append({ 'date': node.getAttribute('date'), 'low': node.getAttribute('low'), 'high': node.getAttribute('high'), 'condition': node.getAttribute('text') }) ycondition = dom.getElementsByTagNameNS(WEATHER_NS, 'condition')[0] return { 'current_condition': ycondition.getAttribute('text'), 'current_temp': ycondition.getAttribute('temp'), 'forecasts': forecasts, 'title': dom.getElementsByTagName('title')[0].firstChild.data } def get(): zip = self.request.get('msg').strip().split(" ")[1] weather = weather_for_zip(zip) day_after_tomorrow = (datetime.date.today() + datetime.timedelta(days=2)).strftime('%A') today = "%s %sF" % (weather['current_condition'], weather['current_temp']) tomorrow = "%s %sF" % (weather['forecasts'][0]['condition'], weather['forecasts'][0]['high']) next_day = "%s %sF" % (weather['forecasts'][1]['condition'], weather['forecasts'][1]['high']) self.render("%s today, %s tomorrow, %s %s" % \ (today, tomorrow, next_day, day_after_tomorrow))
**Description** Hello World demo weblet. **Params** msg (optional) Message to display. If not present, display intro text) **Examples** * <http://qkhack.appspot.com/helloworld> * <http://qkhack.appspot.com/helloworld?msg=hey> Markdown Reference