0

why isn't this working?

import re

import urllib2

from xml.dom import minidom, Node

day_of_week_dic = {

"Mon": "Monday",

"Tue": "Tuesday",

"Wed": "Wednesday",

"Thu": "Thursday",

"Fri": "Friday",

"Sat": "Saturday",

"Sun ": "Sunday ",

"mph":"Milesperhour "

}

def replace_words(text, word_dic):

    rc = re.compile('|'.join(map(re.escape, word_dic)))

    def translate(match):

        return word_dic[match.group(0)]

    return rc.sub(translate, text)

def weather():

    result = ask("Enter or say your five digit zip code",{"choices":"[5 DIGITS]",

            "timeout":30,

            "attempts":3,

            "onBadChoice": lambda event : say("I'm sorry,  I didn't understand that.")})

    urlRead = urllib2.urlopen('http://xml.weather.yahoo.com/forecastrss/%s_f.xml'%result.value)

    xml = minidom.parse(urlRead)

    if xml:

        for channelNode in xml.documentElement.childNodes:

            if channelNode.nodeName == 'channel':

                for itemNode in channelNode.childNodes:

                    if itemNode.nodeName == 'item':

                        for yWeatherNode in itemNode.childNodes:

                            if yWeatherNode.nodeName == 'yweather:forecast':

                                day = replace_words(yWeatherNode.getAttribute('day'), day_of_week_dic)

                                low = yWeatherNode.getAttribute('low')

                                high = yWeatherNode.getAttribute('high')

                                condition = yWeatherNode.getAttribute('text')

                                say("For "+day+", there is a low of "+low+" degrees and a high of "+high+" degrees. The condition is "+condition+".")

            

                        

weather()

hangup()

that's my code. Not sure why it isn't working. I call and it just hangs up. The script works on my desktop.

2 comments

Please sign in to leave a comment.