Esempio n. 1
0
def get_started(message):
    chat_id = message.chat.id

    if get_City(chat_id) is None:
        question(chat_id, 'Please enter your city', check_add_City)
    else:
        bot.send_message(chat_id, 'You already started)')
Esempio n. 2
0
def send_help(message):
    chat_id = message.chat.id
    help_text = messages['help_message']
    for comm, text in commands.items():
        help_text += '/' + comm + ': '
        help_text += text + '\n'
    bot.send_message(chat_id, help_text)
Esempio n. 3
0
def goto_settings(message):
    chat_id = message.chat.id
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    itembtn1 = types.KeyboardButton('Account Settings')
    itembtn2 = types.KeyboardButton('General Settings')
    itembtn3 = types.KeyboardButton('Go Home')
    markup.add(itembtn1, itembtn2, itembtn3)
    bot.send_message(chat_id, "Choose what do you want", reply_markup=markup)
Esempio n. 4
0
def show_account_settings(message):
    chat_id = message.chat.id
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    itembtn1 = types.KeyboardButton('Change City')
    itembtn2 = types.KeyboardButton('Change Degree Unit')
    itembtn3 = types.KeyboardButton('Go Home')
    markup.add(itembtn1, itembtn2, itembtn3)
    bot.send_message(chat_id, "Choose what do you want", reply_markup=markup)
Esempio n. 5
0
def check_City(chat_id, city_name, mess_succ, mess_erros, func):
    try:
        coords = city_to_coord(city_name)
        country, state, city_name = coord_to_city(coords)

        _ = get_data(coords, get_Unit(chat_id))
        change_City(chat_id, city_name)
        change_State(chat_id, state)
        change_County(chat_id, country)
        change_Coords(chat_id, coords)
        bot.send_message(chat_id, messages['check_add_City'],
                         reply_markup=main_forcast_markup())
        bot.send_message(chat_id, "Your current location is\n"
                         + print_location(country, state, city_name))
    except:
        question(chat_id, messages['check_add_City_error'], func)
Esempio n. 6
0
def show_main_forecast(message):
    chat_id = message.chat.id
    try:
        text = 'Here is your forecast:\n'
        coords = get_Coords(chat_id)
        data = get_data(coords, get_Unit(chat_id))
        for key, value in data.items():
            text += key + ": " + str(value) + '\n'
        bot.send_message(chat_id, text)
    except AttributeError:
        if isinDataBase(message.chat.id):
            bot.send_message(chat_id, messages['something_wrong'])
        else:
            bot.send_message(chat_id, messages['get_started_again'])
            add_User(chat_id)
            get_started(message)
Esempio n. 7
0
def send_welcome(message):
    chat_id = message.chat.id
    if not isinDataBase(chat_id):
        add_User(chat_id)
        bot.send_message(chat_id, messages['first_hello'])

        markup = types.ReplyKeyboardMarkup(resize_keyboard=True,
                                           one_time_keyboard=True)
        itembtn1 = types.KeyboardButton('Get Started')
        markup.add(itembtn1)
        bot.send_sticker(chat_id, getSticker('hello_again.webp'))
        bot.send_message(chat_id, messages['get_started'],
                         reply_markup=markup)

    else:
        bot.send_message(chat_id, messages['hello_again'],
                         reply_markup=main_forcast_markup())
        bot.send_sticker(chat_id, getSticker('hello.webp'))
Esempio n. 8
0
def handle_location(message):
    chat_id = message.chat.id
    try:
        coords = str(message.location.latitude) + " " + \
            str(message.location.longitude)
        country, state, city_name = coord_to_city(coords)

        _ = get_data(coords, get_Unit(chat_id))
        change_City(chat_id, city_name)
        change_State(chat_id, state)
        change_County(chat_id, country)
        change_Coords(chat_id, coords)
        bot.send_message(chat_id, messages['check_add_City'],
                         reply_markup=main_forcast_markup())
        bot.send_message(chat_id, "Your current location is\n"
                         + print_location(country, state, city_name))
    except:
        bot.send_message(
            chat_id, "Something went wrong please resend your location")
Esempio n. 9
0
def send_help(message):
    chat_id = message.chat.id
    bot.send_message(chat_id, 'Home, sweet home)',
                     reply_markup=main_forcast_markup())
Esempio n. 10
0
def question(chat_id, message, callback):
    markup = types.ForceReply()
    city = bot.send_message(chat_id, message,
                            reply_markup=markup)
    bot.register_next_step_handler(city, callback)
Esempio n. 11
0
def go_home(message):
    chat_id = message.chat.id
    bot.send_message(chat_id, "Here you go)",
                     reply_markup=main_forcast_markup())
Esempio n. 12
0
def change_user_unit(message):
    markup = InlineKeyboardMarkup()
    markup.row_width = 1
    markup.add(InlineKeyboardButton("Celsius", callback_data="celsius"),
               InlineKeyboardButton("Kelvin", callback_data="kelvin"))
    bot.send_message(message.chat.id, "Which one?", reply_markup=markup)