예제 #1
0
 def getWeatherCurrentConditions(self, xml):
     item = xml.find("channel/item")
     wind = xml.find("channel/{0}wind".format(yweather))
     barometric = xml.find("channel/{0}atmosphere".format(yweather))
     astronomy = xml.find("channel/{0}astronomy".format(yweather))
     currentCondition = item.find("{0}condition".format(yweather))
     
     if currentCondition is None:
         return None
     weatherCondition = WeatherCondition()
     weatherCondition.conditionCodeIndex = int(currentCondition.get("code"))
     weatherCondition.conditionCode = weatherCondition.ConditionCodeIndexTable[weatherCondition.conditionCodeIndex]
     
     current = WeatherCurrentConditions()
     current.dayOfWeek = currentCondition.get("date").split(",")[0]
     current.temperature = currentCondition.get("temp")
     current.barometricPressure = self.getWeatherBarometrics(xml)
     current.condition = weatherCondition
     current.percentHumidity = barometric.get("humidity")
     current.sunrise = astronomy.get("sunrise")
     current.sunset = astronomy.get("sunset")
     current.temperature = currentCondition.get("temp")
     current.timeOfObservation = xml.find("channel/lastBuildDate").text
     current.visibility = barometric.get("visibility")
     current.windChill = wind.get("chill")
     current.windSpeed = self.getWeatherWind(xml)
     return current
예제 #2
0
    def getWeatherCurrentConditions(self, xml):
        item = xml.find("channel/item")
        wind = xml.find("channel/{0}wind".format(yweather))
        barometric = xml.find("channel/{0}atmosphere".format(yweather))
        astronomy = xml.find("channel/{0}astronomy".format(yweather))
        currentCondition = item.find("{0}condition".format(yweather))

        if currentCondition is None:
            return None
        weatherCondition = WeatherCondition()
        weatherCondition.conditionCodeIndex = int(currentCondition.get("code"))
        weatherCondition.conditionCode = weatherCondition.ConditionCodeIndexTable[
            weatherCondition.conditionCodeIndex]

        current = WeatherCurrentConditions()
        current.dayOfWeek = currentCondition.get("date").split(",")[0]
        current.temperature = currentCondition.get("temp")
        current.barometricPressure = self.getWeatherBarometrics(xml)
        current.condition = weatherCondition
        current.percentHumidity = barometric.get("humidity")
        current.sunrise = astronomy.get("sunrise")
        current.sunset = astronomy.get("sunset")
        current.temperature = currentCondition.get("temp")
        current.timeOfObservation = xml.find("channel/lastBuildDate").text
        current.visibility = barometric.get("visibility")
        current.windChill = wind.get("chill")
        current.windSpeed = self.getWeatherWind(xml)
        return current
예제 #3
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 = 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()
예제 #4
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()
예제 #5
0
 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