def habits(message): db = DbHandler() keyboard_habits = keyboards.habits_keyboard() #to_print = create_list(message.chat.id, 'habits') records = db.select_habits(message.chat.id) if len(records) > 0: to_print = 'Your habits:\n' i = 1 for record in records: to_print += str(i) + '\. ' if record[4] == 1: to_print += '~' + record[2] + '~\n' else: to_print += record[2] + "\n" db.add_gener_num_habits(record[0], i) i += 1 bot.send_message(message.chat.id, to_print, reply_markup=keyboard_habits, parse_mode="MarkdownV2") else: kb_habits = Keyboa(items=[{"Add new habit": "new_habit"}]).keyboard bot.send_message(message.chat.id, "You don't have any habits yet", reply_markup=kb_habits)
def create_list(user_id, function): if function == 'habits': db = DbHandler() records = db.select_habits(user_id) elif function == 'goals': db = DbHandler() records = db.select_goals(user_id) if len(records) > 0: to_print1 = f'Your {function}:\n' i = 1 for record in records: to_print1 += str(i) + '\. ' if record[4] == 1: to_print1 += '~' + record[2] + '~\n' else: to_print1 += record[2] + "\n" db.add_gener_num_habits(record[0], i) i += 1 else: to_print1 = None return to_print1