H
H
Herr_Konrad2019-10-02 10:09:47
Amazon Web Services
Herr_Konrad, 2019-10-02 10:09:47

Why is the bot shutting down on AWS?

There is a telegram bot that works continuously. I hosted it on Amazon Web Service (EC2 Instance), I run the script from the terminal, then I use screen to create a session and exit. The bot works stably, but after a few hours (usually the next day) it stops working. What could be the problem?
Bot code:

def films_button(set_of_films, keyboard_markup):          # КЛАВИША ДЛЯ КЛАВИАТУРЫ

    for film in set_of_films:
        keyboard_markup.add(types.KeyboardButton(str(film).strip("()'',")))

    return keyboard_markup


def get_timetable(message):
    a = []
    with sqlite3.connect("movies.db") as con:
        cur = con.cursor()
        for row in cur.execute("SELECT time, cinema FROM movies WHERE movie=(?)", (message, )):
            a.append(row)

    b = re.sub(",", "\n", str(a))
    c = re.sub("[()''[\]]", " ", b)
    return c


conn = sqlite3.connect("movies.db", check_same_thread=False)      # ПОЛУЧЕНИЕ ИНФОРМАЦИИ С БАЗЫ ДАННЫХ
cursor = conn.cursor()
sql = "SELECT movie FROM movies"
cursor.execute(sql)
films_set = set(cursor.fetchall())

bot = telebot.TeleBot('код бота')

markup = types.ReplyKeyboardMarkup(row_width=2, one_time_keyboard=True, resize_keyboard=True)

@bot.message_handler(commands=['start', 'help'])
def get_text_messages(message):
    bot.send_message(message.from_user.id,
                     "Перед вами список фильмов на сегодня. Выберите фильм, "
                     "расписание которого вы хотели бы увидеть: ",
                     reply_markup=films_button(films_set, markup))


@bot.message_handler(func=lambda message: True)
def send_timetable(message):
    markup = types.ReplyKeyboardMarkup(row_width=2, one_time_keyboard=True, resize_keyboard=True)
    except_markup = types.ReplyKeyboardMarkup(row_width=2, one_time_keyboard=True, resize_keyboard=True)
    if len(get_timetable(message.text)) > 4096:
        for x in range(0, len(get_timetable(message.text)), 4096):
            bot.send_message(message.from_user.id, get_timetable(message.text)[x:x + 4096],
                             reply_markup=films_button(films_set, markup))
    else:

        try:
            bot.send_message(message.from_user.id, get_timetable(message.text),
                             reply_markup=films_button(films_set, markup))

        except ApiException:
            bot.send_message(message.from_user.id, "Вы выбрали фильм на который нет сеансов,"
                                                   " попробуйте другой!", reply_markup=films_button(films_set, except_markup))


bot.polling(none_stop=True, interval=0)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question