Exemplo n.º 1
0
    def start(self, callback, message, **kwargs):
        words = message.text.split()

        # Capture args that look like zip codes
        zip_codes = []

        for word in words:
            if weather.is_valid_zip_code(word) and word not in zip_codes:
                zip_codes.append(word)

        # Run only if there is at least one zip code
        if len(zip_codes) > 0:
            logger.debug("start - words are %s" % words)
            # Branch if the user wants the warmest weather
            if any(x in ['warmest', 'hottest'] for x in words):
                weather_list = weather.return_temperatures_list(zip_codes)
                warmest_weather = weather.return_warmest_weather_object_from_list(weather_list)
                if message.channel:
                    if warmest_weather:
                        callback.send_message(channel=message.channel, message="%s (%s) has the warmest weather of %sF" % (warmest_weather.city, warmest_weather.zip_code, warmest_weather.temperature))
            else:
                weather_list = weather.return_temperatures_list(zip_codes)
                if message.channel:
                    if weather_list:
                        for weather_object in weather_list:
                            callback.send_message(channel=message.channel, message=weather_object.return_weather())
                    else:
                        callback.send_message(channel=message.channel, message="No weather data found")
Exemplo n.º 2
0
    def start(self, client, message, **kwargs):
        words = message.text.split()

        # Capture args that look like zip codes
        zip_codes = []

        for word in words:
            if weather.is_valid_zip_code(word) and word not in zip_codes:
                zip_codes.append(word)

        # Run only if there is at least one zip code
        if zip_codes:
            logger.debug("start - words are %s" % words)
            # Branch if the user wants the warmest weather
            if any(x in ['warmest', 'hottest'] for x in words):
                weather_list = weather.return_temperatures_list(zip_codes, self.api_key_weatherunderground, self.api_key_openweathermap, self.max_zip_codes_per_query)
                warmest_weather = weather.return_warmest_weather_object_from_list(weather_list)
                if message.to:
                    if warmest_weather:
                        text = "%s (%s) has the warmest weather of %sF" % (warmest_weather.city, warmest_weather.zip_code, warmest_weather.temperature)
                        client.send_message(text, message.reply(), event=message.event)
            else:
                weather_list = weather.return_temperatures_list(zip_codes, self.api_key_weatherunderground, self.api_key_openweathermap, self.max_zip_codes_per_query)
                if message.to:
                    if weather_list:
                        for weather_object in weather_list:
                            text = weather_object.return_weather()
                            client.send_message(text, message.reply(), event=message.event)
                    else:
                        text = 'No weather data found'
                        client.send_message(text, message.reply(), event=message.event)
Exemplo n.º 3
0
    def trigger_default(self, client, message, **kwargs):
        words = message.text.split()

        # Capture args that look like zip codes
        zip_codes = []

        for word in words:
            if weather.is_valid_zip_code(word) and word not in zip_codes:
                zip_codes.append(word)

        # Run only if there is at least one zip code
        if zip_codes:
            logger.debug('words are %s' % words)
            # Branch if the user wants the warmest weather
            if any(x in ['warmest', 'hottest'] for x in words):
                weather_list = weather.return_temperatures_list(
                    zip_codes, self.api_key_weatherunderground,
                    self.api_key_openweathermap, self.max_zip_codes_per_query)
                warmest_weather = weather.return_warmest_weather_object_from_list(
                    weather_list)
                if message.to:
                    if warmest_weather:
                        text = '%s (%s) has the warmest weather of %sF' % (
                            warmest_weather.city, warmest_weather.zip_code,
                            warmest_weather.temperature)
                        client.send_message(text,
                                            message.reply(),
                                            event=message.event)
            else:
                weather_list = weather.return_temperatures_list(
                    zip_codes, self.api_key_weatherunderground,
                    self.api_key_openweathermap, self.max_zip_codes_per_query)
                if message.to:
                    if weather_list:
                        for weather_object in weather_list:
                            text = weather_object.return_weather()
                            client.send_message(text,
                                                message.reply(),
                                                event=message.event)
                    else:
                        text = 'No weather data found'
                        client.send_message(text,
                                            message.reply(),
                                            event=message.event)