Ejemplo n.º 1
0
def update_user_location(message):
    """Saves or updates the location for the current user"""
    location_stored_correctly = store_user_location(message.from_user,
                                                    message.location)

    if location_stored_correctly:
        answer = LOCATION_STORED_CORRECTLY_ENG if is_bot_English(
        ) else LOCATION_STORED_CORRECTLY_VAL
    else:
        answer = LOCATION_NOT_STORED_CORRECTLY_ENG if is_bot_English(
        ) else LOCATION_NOT_STORED_CORRECTLY_VAL

    # Creating a custom keyboard to simplify the commands entering process
    keyboard = types.ReplyKeyboardMarkup(row_width=2,
                                         one_time_keyboard=False,
                                         resize_keyboard=True)
    if is_bot_English():
        itembtn_umbrella = types.KeyboardButton('/umbrella')
        itembtn_washingmachine = types.KeyboardButton('/washingmachine')
        itembtn_cold = types.KeyboardButton('/cold')
    else:
        itembtn_umbrella = types.KeyboardButton('/paraguas')
        itembtn_washingmachine = types.KeyboardButton('/lavadora')
        itembtn_cold = types.KeyboardButton('/frio')
    keyboard.add(itembtn_umbrella, itembtn_washingmachine, itembtn_cold)

    bot.send_message(message.chat.id, answer, reply_markup=keyboard)
Ejemplo n.º 2
0
def umbrella(message):

    # Getting the current weather
    lat, lon = get_user_location(message.from_user)
    forecast = get_today_forecast_in_location(lat, lon)

    # Not checking the weather if we don't have user's location
    if not forecast:
        ask_user_location(bot, message)
        return None

    # Choosing the language and answering the user
    if forecast.is_bad():
        answer = TODAY_WORRY_ENG if is_bot_English() else TODAY_WORRY_VAL
    else:
        answer = TODAY_NO_WORRY_ENG if is_bot_English() else TODAY_NO_WORRY_VAL
    bot.reply_to(message, answer)
Ejemplo n.º 3
0
def washingmachine(message):
    """Method that indicates if there will be any bad weather in the following 3 days"""

    lat, lon = get_user_location(message.from_user)
    forecast = get_3day_forecast_in_location(lat, lon)

    # Not checking the weather if we don't have user's location
    if not forecast:
        ask_user_location(bot, message)
        return None

    # Choosing the language and answering the user
    if forecast.is_bad():
        answer = FORECAST_WORRY_ENG if is_bot_English() else FORECAST_WORRY_VAL
    else:
        answer = FORECAST_NO_WORRY_ENG if is_bot_English(
        ) else FORECAST_NO_WORRY_VAL
    bot.reply_to(message, answer)
Ejemplo n.º 4
0
def get_commands_help(message):
    """Shows a list of all the current commands"""
    response = HELP_ENG if is_bot_English() else HELP_VAL

    # Creating a custom keyboard to simplify the commands entering process
    keyboard = types.ReplyKeyboardMarkup(row_width=1,
                                         one_time_keyboard=False,
                                         resize_keyboard=True)
    if is_bot_English():
        itembtn_umbrella = types.KeyboardButton('/umbrella')
        itembtn_washingmachine = types.KeyboardButton('/washingmachine')
        itembtn_cold = types.KeyboardButton('/cold')
    else:
        itembtn_umbrella = types.KeyboardButton('/paraguas')
        itembtn_washingmachine = types.KeyboardButton('/lavadora')
        itembtn_cold = types.KeyboardButton('/frio')
    keyboard.add(itembtn_umbrella, itembtn_washingmachine, itembtn_cold)

    bot.send_message(message.chat.id, response, reply_markup=keyboard)
Ejemplo n.º 5
0
def start_and_ask_location(message):
    """Presents itself and asks for the user location"""

    # Setting a "Send location" keyboard button
    if is_bot_English():
        INTRODUCTION_MSG = INTRODUCTION_ENG
        itembtn_location = types.KeyboardButton(
            "Of course I will, no problem bro!", request_location=True)
    else:
        INTRODUCTION_MSG = INTRODUCTION_VAL
        itembtn_location = types.KeyboardButton(
            "Clar que sí home, el que faça falta!", request_location=True)

    keyboard = types.ReplyKeyboardMarkup(row_width=1,
                                         one_time_keyboard=True,
                                         resize_keyboard=True)
    keyboard.add(itembtn_location)
    bot.send_message(message.chat.id, INTRODUCTION_MSG, reply_markup=keyboard)
Ejemplo n.º 6
0
def cold(message):
    """Method that indicates the lowest temperature of the following 24 hours"""

    lat, lon = get_user_location(message.from_user)

    # Not checking the weather if we don't have user's location
    if (lat == -1) and (lon == -1):
        ask_user_location(bot, message)
        return None
    # If we have it, we'll get the min temperature and answering the user
    else:
        temperatures = get_today_temperatures_in_location(lat, lon)
    min_temperature = min(temperatures)

    # Answering to the user
    if is_bot_English():
        answer = LOW_TEMPERATURE_ENG.format(min_temperature)
    else:
        answer = LOW_TEMPERATURE_VAL.format(min_temperature)
    bot.reply_to(message, answer)