def write_stats(bot, update): dp.remove_handler(text_handler) dp.remove_handler(none_work_handler) sql = SQL_worker(database=config.database_name) current_tasks = len( (str(sql.select_task(chat_id)).replace("('", '').replace("',)", '')).split(' ^$^ ')) stats = (str(sql.select_stats(chat_id)).replace("('", '').replace("',)", '')).split('/') try: temp = int(update.message.text) if current_tasks < temp: bot.send_message(chat_id=update.message.chat_id, text="Wrong value") stats[0] = str(int(stats[0]) + temp) stats[1] = str(int(stats[1]) + current_tasks) stats = "/".join(stats) sql.write_new_stats(stats=stats, user_id=update.message.chat_id) sql.write_new_task(task=locale.no_tasks, user_id=update.message.chat_id) bot.send_message(chat_id=update.message.chat_id, text=locale.done) except Exception: bot.send_message(chat_id=update.message.chat_id, text="Something went wrong. I don't understand you.")
def read_stats(bot, update): sql = SQL_worker(database=config.database_name) stats = (str(sql.select_stats(chat_id)).replace("('", '').replace("',)", '')).split('/') bot.send_message(chat_id=update.message.chat_id, text="You done " + stats[0] + " tasks of " + stats[1] + "\nPercentage of completed tasks: " + str(int(stats[0]) / int(stats[1])) + "%.")