Exemple #1
0
    def showCurrentWeatherWithWOEID(self, language, woeid, metric=True):
        # we can only get 2 day weather with woeid that suxx
        weatherLookup = "http://weather.yahooapis.com/forecastrss?w={0}&u={1}".format(
            woeid, "c" if metric else "f")
        result = getWebsite(weatherLookup, timeout=5)
        if result == None:
            self.say(random.choice(errorText[language]))
            self.complete_request()
            return

        result = ElementTree.XML(result)

        #get the item
        item = result.find("channel/item")
        if item is None:
            self.say(random.choice(noDataForLocationText[language]))
            self.complete_request()
            return

        # they change the language code using the other forecast link..
        weatherLocation = None

        match = idFinder.search(item.find("link").text)
        if match != None:
            loc = match.group('locationID')
            weatherLocation = self.getWeatherLocation(loc[:-2], result)
            fiveDayForecast = "http://xml.weather.yahoo.com/forecastrss/{0}.xml".format(
                loc)

            try:
                result = self.getWebsite(fiveDayForecast, timeout=5)
                result = ElementTree.XML(result)
                item = result.find("channel/item")
            except:
                pass

        if weatherLocation == None:
            weatherLocation = self.getWeatherLocation(woeid, result)

        if item is None:
            self.say(random.choice(noDataForLocationText[language]))
            self.complete_request()
            return

        forecast = WeatherObject()
        forecast.currentConditions = self.getWeatherCurrentConditions(result)
        if forecast.currentConditions == None:
            self.say(random.choice(noDataForLocationText[language]))
            self.complete_request()
            return

        forecast.extendedForecastUrl = item.find("link").text
        forecast.units = self.getWeatherUnits(result)
        forecast.view = forecast.ViewDAILYValue
        forecast.weatherLocation = weatherLocation
        forecast.hourlyForecasts = []

        dailyForecasts = []
        for dailyForecast in result.findall(
                "channel/item/{0}forecast".format(yweather)):
            weatherDaily = WeatherDailyForecast()
            weatherDaily.timeIndex = appleWeek[dailyForecast.get("day")]
            weatherDaily.lowTemperature = int(dailyForecast.get("low"))
            weatherDaily.highTemperature = int(dailyForecast.get("high"))
            weatherDaily.isUserRequested = True
            dailyCondition = WeatherCondition()
            dailyCondition.conditionCodeIndex = int(dailyForecast.get("code"))
            dailyCondition.conditionCode = dailyCondition.ConditionCodeIndexTable[
                dailyCondition.conditionCodeIndex]
            weatherDaily.condition = dailyCondition
            dailyForecasts.append(weatherDaily)

        forecast.dailyForecasts = dailyForecasts
        snippet = WeatherForecastSnippet()
        snippet.aceWeathers = [forecast]

        showViewsCMD = UIAddViews(self.refId)
        showViewsCMD.dialogPhase = showViewsCMD.DialogPhaseSummaryValue
        displaySnippetTalk = UIAssistantUtteranceView()
        displaySnippetTalk.dialogIdentifier = "Weather#forecastCommentary"
        countryName = countries[forecast.weatherLocation.countryCode.lower(
        )] if forecast.weatherLocation.countryCode.lower(
        ) in countries else forecast.weatherLocation.countryCode
        displaySnippetTalk.text = displaySnippetTalk.speakableText = random.choice(
            dailyForcast[language]).format(forecast.weatherLocation.city,
                                           countryName)

        showViewsCMD.views = [displaySnippetTalk, snippet]

        self.sendRequestWithoutAnswer(showViewsCMD)
        self.complete_request()
 def showCurrentWeatherWithWOEID(self, language, woeid, metric = True):
     # we can only get 2 day weather with woeid that suxx
     weatherLookup = "http://weather.yahooapis.com/forecastrss?w={0}&u={1}".format(woeid, "c" if metric else "f")
     result = None
     try:
         result = urllib2.urlopen(weatherLookup, timeout=5).read()
     except:
         self.say(random.choice(errorText[language]))
         self.complete_request()
         return
     
     result = ElementTree.XML(result)
     
     #get the item
     item = result.find("channel/item")
     if item is None:
         self.say(random.choice(noDataForLocationText[language]))
         self.complete_request()
         return
     
     # they change the language code using the other forecast link..
     weatherLocation = None
     
     match = idFinder.search(item.find("link").text)
     if match != None:
         loc = match.group('locationID')
         weatherLocation = self.getWeatherLocation(loc[:-2], result)
         fiveDayForecast = "http://xml.weather.yahoo.com/forecastrss/{0}.xml".format(loc)
         try:
             result = urllib2.urlopen(fiveDayForecast, timeout=5).read()
             result = ElementTree.XML(result)
             item = result.find("channel/item")
         except:
             pass
     
     if weatherLocation == None:
         weatherLocation = self.getWeatherLocation(woeid, result)
     
     if item is None:
         self.say(random.choice(noDataForLocationText[language]))
         self.complete_request()
         return
     
     forecast = WeatherObject()
     forecast.currentConditions = self.getWeatherCurrentConditions(result)
     if forecast.currentConditions == None:
         self.say(random.choice(noDataForLocationText[language]))
         self.complete_request()
         return
     
     forecast.extendedForecastUrl = item.find("link").text
     forecast.units = self.getWeatherUnits(result)
     forecast.view = forecast.ViewDAILYValue
     forecast.weatherLocation = weatherLocation
     forecast.hourlyForecasts = []
     
     dailyForecasts = []
     for dailyForecast in result.findall("channel/item/{0}forecast".format(yweather)):
         weatherDaily = WeatherDailyForecast()
         weatherDaily.timeIndex = appleWeek[dailyForecast.get("day")]
         weatherDaily.lowTemperature = int(dailyForecast.get("low"))
         weatherDaily.highTemperature = int(dailyForecast.get("high"))
         weatherDaily.isUserRequested = True
         dailyCondition = WeatherCondition()
         dailyCondition.conditionCodeIndex = int(dailyForecast.get("code"))
         dailyCondition.conditionCode = dailyCondition.ConditionCodeIndexTable[dailyCondition.conditionCodeIndex]
         weatherDaily.condition = dailyCondition
         dailyForecasts.append(weatherDaily)
 
     forecast.dailyForecasts = dailyForecasts
     snippet = WeatherForecastSnippet()
     snippet.aceWeathers = [forecast]
     
     showViewsCMD = UIAddViews(self.refId)
     showViewsCMD.dialogPhase = showViewsCMD.DialogPhaseSummaryValue
     displaySnippetTalk = UIAssistantUtteranceView()
     displaySnippetTalk.dialogIdentifier = "Weather#forecastCommentary"
     countryName = countries[forecast.weatherLocation.countryCode.lower()] if forecast.weatherLocation.countryCode.lower() in countries else forecast.weatherLocation.countryCode
     displaySnippetTalk.text = displaySnippetTalk.speakableText = random.choice(dailyForcast[language]).format(forecast.weatherLocation.city, countryName)
     
     showViewsCMD.views = [displaySnippetTalk, snippet]
     
     self.sendRequestWithoutAnswer(showViewsCMD)
     self.complete_request()
 def showCurrentWeatherWithWOEID(self, language, woeid, metric = True, readTemp = False):
     # we can only get 2 day weather with woeid that suxx
     weatherLookup = "http://weather.yahooapis.com/forecastrss?w={0}&u={1}".format(woeid, "c" if metric else "f")
     result = getWebsite(weatherLookup, timeout=5)
     if result == None:
         self.say(random.choice(errorText[language]))
         self.complete_request()
         return
     
     result = ElementTree.XML(result)
     
     #get the item
     item = result.find("channel/item")
     if item is None:
         self.say(random.choice(noDataForLocationText[language]))
         self.complete_request()
         return
     
     # they change the language code using the other forecast link..
     weatherLocation = None
     
     match = idFinder.search(item.find("link").text)
     if match != None:
         loc = match.group('locationID')
         weatherLocation = self.getWeatherLocation(loc[:-2], result)
         fiveDayForecast = "http://xml.weather.yahoo.com/forecastrss/{0}.xml".format(loc)
         
         try:
             result = getWebsite(fiveDayForecast, timeout=5)
             result = ElementTree.XML(result)
             item = result.find("channel/item")
         except:
             pass
     
     if weatherLocation == None:
         weatherLocation = self.getWeatherLocation(woeid, result)
     
     if item is None:
         self.say(random.choice(noDataForLocationText[language]))
         self.complete_request()
         return
     
     forecast = WeatherObject()
     forecast.currentConditions = self.getWeatherCurrentConditions(result)
     if forecast.currentConditions == None:
         self.say(random.choice(noDataForLocationText[language]))
         self.complete_request()
         return
     
     forecast.extendedForecastUrl = item.find("link").text
     forecast.units = self.getWeatherUnits(result)
     forecast.view = forecast.ViewDAILYValue
     forecast.weatherLocation = weatherLocation
     forecast.hourlyForecasts = []
     
     dailyForecasts = []
     for dailyForecast in result.findall("channel/item/{0}forecast".format(yweather)):
         weatherDaily = WeatherDailyForecast()
         weatherDaily.timeIndex = appleWeek[dailyForecast.get("day")]
         weatherDaily.lowTemperature = int(dailyForecast.get("low"))
         weatherDaily.highTemperature = int(dailyForecast.get("high"))
         weatherDaily.isUserRequested = True
         dailyCondition = WeatherCondition()
         dailyCondition.conditionCodeIndex = int(dailyForecast.get("code"))
         dailyCondition.conditionCode = dailyCondition.ConditionCodeIndexTable[dailyCondition.conditionCodeIndex]
         weatherDaily.condition = dailyCondition
         dailyForecasts.append(weatherDaily)
 
     forecast.dailyForecasts = dailyForecasts
     return forecast