Answer the question
In order to leave comments, you need to log in
How to save message in sqlite after clicking on inline button?
My bot parses photos from pinterest and sends them as a link, there is an inline button below them, I want the link to be added to the database after clicking on it, and then displayed in the profile
for _ in range(1,ScrollNumber):
driver.execute_script("window.scrollTo(1,10000)")
time.sleep(sleepTimer)
soup = BeautifulSoup(driver.page_source,'html.parser')
for link in soup.find_all('img'):
src = link.get('src')
if src.find("/236x/") != -1:
src = src.replace("/236x/","/originals/")
elif src.find(".gif") != -1:
markup = telebot.types.InlineKeyboardMarkup()
markup.add(telebot.types.InlineKeyboardButton(text='Сохранить❔', callback_data="save"))
bot.send_message(message.chat.id, src, reply_markup=markup)
else:
pass
bot.send_message(message.chat.id,"CPU USED TO PARSE -" + str(psutil.cpu_percent()) + "%")
@bot.callback_query_handler(func=lambda call: True)
def query_handler(call):
if call.data == 'save':
markup = telebot.types.InlineKeyboardMarkup()
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Сохранен в профиль.✅", reply_markup=markup)
Answer the question
In order to leave comments, you need to log in
Is the link sent in text?
In your query_handler function, you can get the text of the original message (in this case, it's a link) via call.mesaage.text, then save it to the database
What is the problem? You track the click on the button, when you click, save the file to your computer, write the path to it in the database.
hey_umbrella , I'm not at the PC now. Pass the required parameter to callback
That is, where callback_data="save"
Do this:
callback_data=f"save_{src}"
Then you can easily read the text from the button:
if call.data == 'save':
call_text = call.data.split (“save_”)[-1]
print(call_text)
How to add inline keyboard response to database?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question