Доброй ночи!
Прошу Вас помощи, есть телеграмм бот
Мне нужно убрать раздел ассортимент, перед ним наделать категории, а потом уже в те категории добавлять товар, столько усилий проделал, все безрезультатно, то python ругается
то кнопки в боте перестают работать
root@bot:~# python3 main.py
python3 functions.py
Traceback (most recent call last):
File "main.py", line 891, in
start_bot()
File "main.py", line 887, in start_bot
bot.polling(none_stop=True)
File "/usr/local/lib/python3.6/dist-packages/telebot/__init__.py", line 455, in polling
self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout)
File "/usr/local/lib/python3.6/dist-packages/telebot/__init__.py", line 513, in __threaded_polling
raise e
File "/usr/local/lib/python3.6/dist-packages/telebot/__init__.py", line 479, in __threaded_polling
self.worker_pool.raise_exceptions()
File "/usr/local/lib/python3.6/dist-packages/telebot/util.py", line 118, in raise_exceptions
raise self.exception_info
File "/usr/local/lib/python3.6/dist-packages/telebot/util.py", line 69, in run
task(*args, **kwargs)
File "main.py", line 55, in handler_call
reply_markup=func.menu_subcategory()
AttributeError: module 'functions' has no attribute 'menu_subcategory'
root@bot:~# python3 functions.py
root@bot:~# module 'functions' has no attribute 'menu_subcategory'
from telebot import types
import sqlite3
import telebot
import os
import settings
import random
import requests
import json
import datetime
class Catalog:
def __init__(self, name):
self.name = name
class SubCategory:
def __init__(self, subcategory):
self.subcategory = name
class Product:
def __init__(self, user_id):
self.user_id = user_id
self.product = None
self.section = None
self.price = None
self.amount = None
self.amount_MAX = None
self.code = None
class AddProduct:
def __init__(self, section):
self.section = section
self.product = None
self.price = None
self.info = None
class DownloadProduct:
def __init__(self, name_section):
self.name_section = name_section
self.name_product = None
class GiveBalance:
def __init__(self, login):
self.login = login
self.balance = None
self.code = None
class Admin_sending_messages:
def __init__(self, user_id):
self.user_id = user_id
self.text = None
# Menu catalog
def menu_catalog():
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
cursor.execute('SELECT * FROM catalog')
row = cursor.fetchall()
menu = types.InlineKeyboardMarkup(row_width=1)
for i in row:
menu.add(types.InlineKeyboardButton(text=f'{i[0]}', callback_data=f'{i[1]}'))
menu.add(types.InlineKeyboardButton(text='Назад', callback_data='exit_to_menu'))
cursor.close()
conn.close()
return menu
# Menu rayon
def menu_subcategory():
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
cursor.execute('SELECT * FROM rayon')
row = cursor.fetchall()
menu = types.InlineKeyboardMarkup(row_width=1)
for i in row:
menu.add(types.InlineKeyboardButton(text=f'{i[0]}', callback_data=f'{i[1]}'))
menu.add(types.InlineKeyboardButton(text='Назад', callback_data='exit_to_menu'))
cursor.close()
conn.close()
return menu
# Menu section
def menu_section(name_section):
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
cursor.execute(f"SELECT * FROM '{name_section}' ")
row = cursor.fetchall()
menu = types.InlineKeyboardMarkup(row_width=1)
for i in row:
menu.add(types.InlineKeyboardButton(text=f'{i[0]}', callback_data=f'{i[2]}'))
menu.add(types.InlineKeyboardButton(text='Назад', callback_data='exit_to_menu'))
cursor.close()
conn.close()
return menu
# Menu product
def menu_product(product, dict):
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
row = cursor.execute(f'SELECT * FROM section WHERE code = "{product}"').fetchone()
section = row[1]
info = row[3]
amount = len(cursor.execute(f'SELECT * FROM "{product}"').fetchall())
cursor.execute(f'SELECT * FROM "{section}" WHERE code = "{product}"')
row = cursor.fetchone()
dict.section = section
dict.product = product
dict.amount_MAX = amount
dict.price = row[1]
text = settings.text_purchase.format(
name=row[0],
info=info,
price=row[1],
amount=amount
)
return text, dict
# Admin menu - add_to_section_to_catalog
def add_section_to_catalog(name_section):
# Connection
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
code = random.randint(11111, 99999)
# Add
cursor.execute(f"INSERT INTO catalog VALUES ('{name_section}', '{code}')")
conn.commit()
# Create table section
conn.execute(f"CREATE TABLE '{code}' (list text, price text, code text)")
# Close connection
cursor.close()
conn.close()
# Admin menu - add_to_rayon_to_catalog
def add_subcategory_to_catalog(name_subcategory):
# Connection
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
code = random.randint(1111, 9999)
# Add
cursor.execute(f"INSERT INTO catalog VALUES ('{rayon}', '{code}')")
conn.commit()
# Create table section
conn.execute(f"CREATE TABLE '{code}' (list text, price text, code text)")
# Close connection
cursor.close()
conn.close()