Hello,
How can i get the CDATA values?
I am trying this and its outputting 'None':
def get_weather_condition():
weathercondition = None
from xml.dom import minidom
import urllib2
source =
urllib2.urlopen('http://free.worldweatheronline.com/feed/weather.ashx?q=udupi&format=xml&num_of_days=2&key=b019cd7d6a135850110711')
source_text = source.read()
parseddata = minidom.parseString(source_text)
weatherDesc = parseddata.getElementsByTagName('weatherDesc')
weatherDesc1 = parseddata.getElementsByTagName('![CDATA[]]')
if weatherDesc1:
weathercondition = weatherDesc1[0].firstChild.toxml()
return weathercondition
regards
Praveen
On Saturday, March 10, 2012 3:07:29 PM UTC+5:30, rochacbruno wrote:
>
> put the code in models, /models/temp.py
>
> >>> def get_temp():
> ... temp = None
> ... from xml.dom import minidom
> ... source = urllib2.urlopen('
> http://free.worldweatheronline.com/feed/weather.ashx?q=udupi&format=xml&num_of_days=2&key=b019cd7d6a135850110711
> ')
> ... source_text = source.read()
> ... parseddata = minidom.parseString(source_
> text)
> ... temp_c = parseddata.getElementsByTagName('temp_C')
> ... if temp_c:
> ... temp = temp_c[0].firstChild.toxml()
> ... return temp
>
>
> So in any view you can do:
>
> {{=get_temp()}}
>
> also you can access it in any controller
>
> def index():
> temp = get_temp()
> return dict(temp=temp)
>
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>