Skip to content

Instantly share code, notes, and snippets.

@gladson
Created November 29, 2011 14:32
Show Gist options
  • Select an option

  • Save gladson/1404998 to your computer and use it in GitHub Desktop.

Select an option

Save gladson/1404998 to your computer and use it in GitHub Desktop.
fdsgdfgdf123
from django.shortcuts import render_to_response
from django.template import RequestContext
import urllib
from xml.dom import minidom
def google_weather(request):
GOOGLE_WEATHER_URL = 'http://www.weather.com/xml'
GOOGLE_IMG_ROOT = 'http://10.2.2.106/media'
url = GOOGLE_WEATHER_URL
weather = {}
dom = minidom.parse(urllib.urlopen(url))
weather['city'] = get_data(dom, "city")
weather['icon'] = GOOGLE_IMG_ROOT + get_data(dom, "icon")
weather['wind_condition'] = get_data(dom, "wind_condition")
forecasts = []
for node in dom.getElementsByTagName("forecast_conditions"):
forecast = {
'day_of_week': get_data(node, "day_of_week"),
'low': get_data(node, "low"),
'high': get_data(node, "high"),
'icon': GOOGLE_IMG_ROOT + get_data(node, "icon"),
'condition': get_data(node, "condition"),
}
forecasts.append(forecast)
weather['forecasts'] = forecasts
#return weather
return render_to_response('rondoniacafe/weather/weather.html',{
'weather': weather
},
context_instance=RequestContext(request)
)
def get_data(dom, tag):
return dom.getElementsByTagName(tag)[0].getAttribute("data")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment