V
V
Vova Efanov2021-05-13 18:40:40
Python
Vova Efanov, 2021-05-13 18:40:40

Writes None in the rating?

Hello, forum users, there is a problem with the rating section in the telegram bot, writes None although I'm trying to display user data by his id in the rating, here is the code:

def get_top_surviveds(self, id):
  with self.connection:
    self.cursor.execute("SELECT survived FROM stats WHERE user_id = ?", (id, )).fetchone()
    self.connection.commit()

bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Топ выживших\n Андрей - {0}\n Вова - {1}\n Максим - {2}'.format(sql_lighter.get_top_surviveds(754651730), sql_lighter.get_top_surviveds(982543922), sql_lighter.get_top_surviveds(1720547162)), reply_markup=menu)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dimonchik, 2021-05-13
@dimonchik2013

the code is good, but None can really be
done check, change to 0 (zero) if None or re-request if you need a rating

G
galaxy, 2021-05-13
@galaxy

And what does the get_top_surviveds() function return?

O
o5a, 2021-05-13
@o5a

So the function doesn't return anything. If you need top N, then you can simply immediately return N rows with all data using limit

def get_top_surviveds(self, limit=3):
  with self.connection:
    return self.cursor.execute("SELECT * FROM stats ORDER BY survived desc LIMIT ?", (limit, )).fetchall()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question