import telebot
import sqlite3
import os
from telebot import types
botTimeWeb = telebot.TeleBot('токен')
db_path = os.path.join(os.getcwd(), "TeleBot", "math_tasks.db")
@botTimeWeb.message_handler(commands=['start'])
def startBot(message):
first_mess = f"{message.from_user.first_name} {message.from_user.last_name}, Привет! Ты готов начать заниматься?"
markup = types.InlineKeyboardMarkup()
button_yes = types.InlineKeyboardButton(text='Да', callback_data='yes')
markup.add(button_yes)
botTimeWeb.send_message(message.chat.id, first_mess, parse_mode='html', reply_markup=markup)
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS math_tasks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
task_image BLOB NOT NULL,
answer_text TEXT NOT NULL
)
''')
conn.commit()
conn.close()
def insert_task(image_path, answer_text):
try:
with open(image_path, 'rb') as file:
image_blob = file.read()
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('''
INSERT INTO math_tasks (task_image, answer_text)
VALUES (?, ?)
''', (image_blob, answer_text))
conn.commit()
conn.close()
print("Задача успешно добавлена.")
except Exception as e:
print(f"Ошибка при вставке задачи: {e}")
image_path = "задачи егэ №1/scale_1200.png"
answer_text = "38,75"
insert_task(image_path, answer_text)
@botTimeWeb.callback_query_handler(func=lambda call: True)
def response(call):
if call.message:
if call.data == "yes":
second_mess = "Какой номер ты хочешь решить из первой части?"
markup = types.InlineKeyboardMarkup()
buttons = [
types.InlineKeyboardButton(text=str(i), callback_data=str(i)) for i in range(1, 13)
]
markup.add(*buttons)
botTimeWeb.send_message(call.message.chat.id, second_mess, reply_markup=markup)
botTimeWeb.answer_callback_query(call.id)
botTimeWeb.infinity_polling()