def _resolve_pws(location): """Look up the location of a PWS.""" if location.lower().startswith("pws:"): wunderground = utils.get_config("Wunderground") api_key = wunderground.get("key") w = pywunderground.request(api_key, ["conditions"], location) return w["current_observation"]["display_location"]["zip"] return location
def weather(self, message, params=None, **kwargs): """Display current weather report (ex: .w [set] [<location>])""" wunderground = utils.get_config("Wunderground") api_key = wunderground.get("key") if params: location = params if location.startswith("set "): location = location[4:] utils.write_file(self.name, message.source, location) message.dispatch("Location information saved") else: location = utils.read_file(self.name, message.source) if not location: message.dispatch(self.weather.__doc__) return try: w = pywunderground.request(api_key, ["conditions"], location) except Exception: message.dispatch("Unable to fetch weather data") return if w.get("current_observation"): w = w["current_observation"] city = w["display_location"]["full"] zip_code = w["display_location"]["zip"] temp = w["temperature_string"] humidity = w["relative_humidity"] wind = w["wind_string"] condition = w["weather"] zip_code = "" if zip_code == "00000" else " %s" % zip_code humidity = "N/A%" if len(humidity) > 3 else humidity result = ("%s%s: %s Humidity: %s Wind: %s %s") % (city, zip_code, temp, humidity, wind, condition) message.dispatch(result) else: message.dispatch("Location not found: '%s'" % location)
def weather(self, message, params=None, **kwargs): """Display current weather report (ex: .w [set] [<location>])""" wunderground = utils.get_config("Wunderground") api_key = wunderground.get("key") if params: location = params if location.startswith("set "): location = location[4:] utils.write_file(self.name, message.source, location) message.dispatch("Location information saved") else: location = utils.read_file(self.name, message.source) if not location: message.dispatch(self.weather.__doc__) return try: w = pywunderground.request(api_key, ["conditions"], location) except Exception: message.dispatch("Unable to fetch weather data") return if w.get("current_observation"): w = w["current_observation"] city = w["display_location"]["full"] zip_code = w["display_location"]["zip"] temp = w["temperature_string"] humidity = w["relative_humidity"] wind = w["wind_string"] condition = w["weather"] zip_code = "" if zip_code == "00000" else " %s" % zip_code humidity = "N/A%" if len(humidity) > 3 else humidity result = ("%s%s: %s Humidity: %s Wind: %s %s") % ( city, zip_code, temp, humidity, wind, condition) message.dispatch(result) else: message.dispatch("Location not found: '%s'" % location)
def format_tts(self): if not self.data: logger.debug(u'Fetching data from wunderground...') self.data = pywunderground.request(API_KEY, ['conditions', 'forecast'], self.query) return self.tts.format(**self.data)