Hi, I am experimenting with a Telegram bot application where in one case I need to sequentially send information by increasing one index when the user push a determined button.
So, I've defined a global variable count which I initialize as zero at the beginning of flask_app.py.
The thing is that in a random way and while count is indexing and having any value, upon a POST request , the value goes to zero making the DB search fail. As Telegram keeps sending the POST until having a 200 response, I can see the variable is going back to the expected increased index value. Sometimes, it takes like two or three request.
How can avoid or work around on this?
Does flask_app.py starts from the beginning sometimes ? I understand it must start after the @app.route() function.
if query: chat_id = query.message.chat_id bot.sendMessage(chat_id=chat_id, text='<b>Rec Button on count = </b>' + str(count) , parse_mode=telegram.ParseMode.HTML) ss = "SELECT Stat FROM RIGS WHERE ID = " + str(count) c.execute(ss) all_rows = c.fetchall() n = all_rows statt = n if query.data == '1': data = 'DOSOK' elif query.data == '2': data = 'CHECK' elif query.data == '3': data = 'NOLOG' elif query.data == '4': data = statt update_query = " UPDATE RIGS SET Stat = " + "'" + data + "'" + "WHERE ID = " + "'"+ str(count) + "'" #update_query = " UPDATE RIGS SET Stat = " + data + "WHERE ID = " + "'" + str(count) + "'" c.execute(update_query) conn.commit() count = count + 1 if count == 36: count =1 #conn.commit() Select_info(count, chat_id, reply_markup)
count is initialized as zero at the beginning and defined as global in the app as shown on below partial code.
@app.route('/', methods=['POST']) def webhook_handler(): global count global SM if request.method == "POST":
Thanks a million for any help!