Всем добра!
Возникла идея-надобность в телеграмм-боте, опыта в питоне маловато (нет фактически), поэтому прошу помочь:
Основная идея создать бота, который сканируя QR-код, передает расшифрованный текст из QR-кода, id и комментарий пользователя в excel
при выполнении строки:
Код:
context.bot.register_next_step_handler(msg.chat_id, get_TItog)
возникает ошибка: 'ExtBot' object has no attribute 'register_next_step_handler'
Сам код:
Код:
import telebot
from telebot import types
import pandas as pd
from time import strftime, time
from time import sleep, time
import datetime
#https://t.me/GSPMUMiT_bot #GSPM-UMiT
# Telegram
from operator import index
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import Updater, Filters, MessageHandler, CallbackContext
# QR Code
from pyzbar.pyzbar import decode
# System libraries
import os
from os import listdir
from os.path import isfile, join
import pandas as pd
from io import BytesIO
from PIL import Image
mylist = [5331122166, 897142962]
BOT_TOKEN='token'
bot=telebot.TeleBot(BOT_TOKEN)
wTech=''
rTech=''
sTech=''
iTech=''
oTech=''
otTech=''
@bot.message_handler(commands=['start'])
def handle_start(message):
stic = open('C:/Projects/UMIT/stic/logo.webp', 'rb')
# клавиатура
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
but1 = types.KeyboardButton("Техника")
but2 = types.KeyboardButton("Сотрудники")
but3 = types.KeyboardButton("Другое")
markup.add(but1, but2, but3)
fName = message.from_user.username
dt_now = datetime.datetime.now()
iTech=message.id
oTech=message.first_name
bot.reply_to(message, "Добрый день, {0.first_name}\nВыберите раздел" .format(message.from_user),parse_mode='html',reply_markup=markup) #, 0.id 0.first_name, 0.last_name, 0.phone_number
bot.reply_to(message, dt_now)
bot.send_sticker(message.chat.id,stic)
#Сканер QR
QRtxt = ''
def decode_qr(update: Update, context: CallbackContext):
chat_id = update.message.chat_id
if update.message.photo:
id_img = update.message.photo[-1].file_id
else:
return
foto = context.bot.getFile(id_img)
new_file = context.bot.get_file(foto.file_id)
new_file.download('qrcode.png')
try:
result = decode(Image.open('qrcode.png'))
#context.bot.sendMessage(chat_id=chat_id, text=result[0].data.decode("utf-8")) #Оригинал
messg = result[0].data.decode("utf-8")
print(messg)
wTech = messg.split(";")[0]
rTech = messg.split(";")[1]
sTech = messg.split(";")[2]
msg = context.bot.sendMessage(chat_id=chat_id, text=result[0].data.decode("utf-8")) #context.bot.reply_to(messg, "Комментарий")
context.bot.register_next_step_handler(msg.chat_id, get_TItog)
os.remove("qrcode.png")
except Exception as e:
print(str(e))
context.bot.sendMessage(chat_id=chat_id, text=str(e))
#Передача в excel
def get_TItog(message):
salaries1 = pd.DataFrame({'Показатель': ['Номер ПЛ', 'Гар№', 'ФИО', 'iD', 'Name', 'Другое'],
'Кол-во': [wTech, rTech, sTech, iTech, oTech, otTech]})
#print(salaries1)
filename1 = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
NewName = filename1+'.xlsx'
writer = pd.ExcelWriter('C:/Projects/UMIT/OP/'+NewName, engine='xlsxwriter')
salaries1.to_excel('./teams.xlsx', sheet_name='Budgets', index=False)
writer.save()
def main():
updater = Updater(BOT_TOKEN, request_kwargs={'read_timeout': 20, 'connect_timeout': 20}, use_context=True)
dp = updater.dispatcher
dp.add_handler(MessageHandler(Filters.photo, decode_qr))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
bot.polling(none_stop=True)
Буду очень признателен за помощь!