Всем привет, пишу бота обрабатывающего картинки присылая текст с них и столкнулся с проблемой из функции handler_file не переходит к get_languagе, что делать?
bot = telebot.TeleBot(bot_token, parse_mode='html')
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
name = None
photo_list = []
def PhotoSave(imag, message, language='rus'):
img = Image.open(imag)
file_name = img.filename
file_name = file_name.split(".")[0]
text = pytesseract.image_to_string(img, lang=language).strip()
bot.reply_to(message, text)
@bot.message_handler(commands=['start'])
def send_welcome(message):
send = bot.send_message(message.from_user.id, 'Присылай фото')
bot.register_next_step_handler(send, handler_file)
return
@bot.message_handler(content_types=['photo', 'document'])
def handler_file(message):
from pathlib import Path
Path(f'files/{message.chat.id}/').mkdir(parents=True, exist_ok=True)
if message.content_type == 'photo':
file_info = bot.get_file(message.photo[len(message.photo) - 1].file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = f'files/{message.chat.id}/' + file_info.file_path.replace('photos/', '')
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
send = bot.send_message(message.chat.id, f'Фото вос бин сохранен!')
elif message.content_type == 'document':
file_info = bot.get_file(message.document.file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = f'files/{message.chat.id}/' + message.document.file_name
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
send = bot.send_message(message.chat.id, f'Файл вос бин сохранен!')
else:
send = bot.send_message(message.chat.id, f'пришлите фото')
bot.register_next_step_handler(send, get_language)
return
def get_language(message):
msg = bot.send_message(message.chat.id, f'Загружаю...')
bot.delete_message(message.chat.id, msg.message_id)
markup = types.InlineKeyboardMarkup(row_width=2)
item1 = types.InlineKeyboardButton("Русский", callback_data='rus')
item2 = types.InlineKeyboardButton("Английский", callback_data='en')
bot.send_message(message.chat.id, 'Выберите язык', reply_markup=markup)
markup.add(item1, item2)
return
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
language = None
try:
if call.message:
if call.data == 'rus':
bot.send_message(call.message.chat.id, 'РУССКИЙ')
elif call.data == 'en':
bot.send_message(call.message.chat.id, 'АНГЛИЙСКИЙ')
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
text="Выберите язык",
reply_markup=None)
# show alert
bot.answer_callback_query(callback_query_id=call.id, show_alert=False,
text=f"Вы выбрали{call.data}")
except Exception as e:
print(repr(e))
bot.polling(none_stop=True)
Заранее спасибо