bot.py import telebot import sqlite3 import keyboards import requests import json bot = telebot.TeleBot("токен бота телеграм") conn = sqlite3.connect('oplata.sqlite', check_same_thread=False) c = conn.cursor() c.execute('CREATE TABLE opl (id int, sum varchar, komment varchar)') @bot.message_handler(commands=['start', 'help']) def send_welcome(message): bot.send_message(message.chat.id, "Добро пожаловать!", reply_markup=keyboards.main_keyboard()) @bot.message_handler(content_types=['text']) def handle_text(message): id = message.chat.id tx = message.text if tx == ' Каталог товаров': bot.send_message(id, 'Список товаров', reply_markup=keyboards.list_keyboard()) if tx == keyboards.tovar1: komment = keyboards.generate_komment() c.execute("INSERT INTO opl (id, sum, komment) VALUES ('%s','%s','%s')"%(str(id),keyboards.tovar1price,komment)) conn.commit() bot.send_message(id, '', reply_markup=keyboards.oplata_keyboard('https://****.com/payment/form/99?extra%5B%27account%27%5D='+ keyboards.qiwi_number +'¤cy=643&comment='+ komment +'&amountInteger='+ str(keyboards.tovar1price) +'&amountFraction=0&blocked%5B0%5D=account&blocked%5B1%5D=comment&blocked%5B2%5D=sum')) elif tx == keyboards.tovar2: komment = keyboards.generate_komment() c.execute("INSERT INTO opl (id, sum, komment) VALUES ('%s','%s','%s')"%(str(id),keyboards.tovar2price,komment)) conn.commit() bot.send_message(id, '', reply_markup=keyboards.oplata_keyboard('https://****.com/payment/form/99?extra%5B%27account%27%5D='+ keyboards.qiwi_number +'¤cy=643&comment='+ komment +'&amountInteger='+ str(keyboards.tovar2price) +'&amountFraction=0&blocked%5B0%5D=account&blocked%5B1%5D=comment&blocked%5B2%5D=sum')) elif tx == keyboards.tovar1: komment = keyboards.generate_komment() c.execute("INSERT INTO opl (id, sum, komment) VALUES ('%s','%s','%s')"%(str(id),keyboards.tovar3price,komment)) conn.commit() bot.send_message(id, '', reply_markup=keyboards.oplata_keyboard('https://****.com/payment/form/99?extra%5B%27account%27%5D='+ keyboards.qiwi_number +'¤cy=643&comment='+ komment +'&amountInteger='+ str(keyboards.tovar3price) +'&amountFraction=0&blocked%5B0%5D=account&blocked%5B1%5D=comment&blocked%5B2%5D=sum')) @bot.callback_query_handler(func=lambda message:True) def ans(message): chat_id = message.message.chat.id oplata = False if message.data == "check_oplata": c.execute("SELECT * FROM opl WHERE id = ('%s')"%(chat_id)) row = c.fetchone() comment = row[2] price = row[1] s = requests.Session() s.headers[u'authorization'] = u'Bearer ' + keyboards.qiwi_token parameters = {'rows': '28'} h = s.get(u'https://edge.****.com/payment-history/v1/persons/'+keyboards.qiwi_number+'/payments', params = parameters) req = json.loads(h.text) for i in range(len(req[u'data'])): suma = req['data'][i]['sum']['amount'] com = req['data'][i]['comment'] if (com == comment) and (int(price) == int(suma)): oplata = True c.execute("DELETE * FROM opl WHERE id = ('%s')"%(chat_id)) #тут ваши действия после оплаты break else: oplata = False if oplata == False: bot.send_message(chat_id, "❕ Платеж еще не дошел, повторите попытку позже", reply_markup=keyboards.oplata_keyboard('https://****.com/payment/form/99?extra%5B%27account%27%5D='+ keyboards.qiwi_number +'¤cy=643&comment='+ comment +'&amountInteger='+ price +'&amountFraction=0&blocked%5B0%5D=account&blocked%5B1%5D=comment&blocked%5B2%5D=sum')) elif message.data == "otmena_oplata": c.execute("SELECT * FROM opl WHERE id = ('%s')"%(chat_id)) bot.send_message(message.chat.id, " ", reply_markup=keyboards.main_keyboard()) elif message.data == "otmena_oplata": bot.send_message(message.chat.id, " ", reply_markup=keyboards.main_keyboard()) bot.polling(none_stop=True) Код import telebot import sqlite3 import keyboards import requests import json bot = telebot.TeleBot("токен бота телеграм") conn = sqlite3.connect('oplata.sqlite', check_same_thread=False) c = conn.cursor() c.execute('CREATE TABLE opl (id int, sum varchar, komment varchar)') @bot.message_handler(commands=['start', 'help']) def send_welcome(message): bot.send_message(message.chat.id, "Добро пожаловать!", reply_markup=keyboards.main_keyboard()) @bot.message_handler(content_types=['text']) def handle_text(message): id = message.chat.id tx = message.text if tx == ' Каталог товаров': bot.send_message(id, 'Список товаров', reply_markup=keyboards.list_keyboard()) if tx == keyboards.tovar1: komment = keyboards.generate_komment() c.execute("INSERT INTO opl (id, sum, komment) VALUES ('%s','%s','%s')"%(str(id),keyboards.tovar1price,komment)) conn.commit() bot.send_message(id, '', reply_markup=keyboards.oplata_keyboard('https://****.com/payment/form/99?extra%5B%27account%27%5D='+ keyboards.qiwi_number +'¤cy=643&comment='+ komment +'&amountInteger='+ str(keyboards.tovar1price) +'&amountFraction=0&blocked%5B0%5D=account&blocked%5B1%5D=comment&blocked%5B2%5D=sum')) elif tx == keyboards.tovar2: komment = keyboards.generate_komment() c.execute("INSERT INTO opl (id, sum, komment) VALUES ('%s','%s','%s')"%(str(id),keyboards.tovar2price,komment)) conn.commit() bot.send_message(id, '', reply_markup=keyboards.oplata_keyboard('https://****.com/payment/form/99?extra%5B%27account%27%5D='+ keyboards.qiwi_number +'¤cy=643&comment='+ komment +'&amountInteger='+ str(keyboards.tovar2price) +'&amountFraction=0&blocked%5B0%5D=account&blocked%5B1%5D=comment&blocked%5B2%5D=sum')) elif tx == keyboards.tovar1: komment = keyboards.generate_komment() c.execute("INSERT INTO opl (id, sum, komment) VALUES ('%s','%s','%s')"%(str(id),keyboards.tovar3price,komment)) conn.commit() bot.send_message(id, '', reply_markup=keyboards.oplata_keyboard('https://****.com/payment/form/99?extra%5B%27account%27%5D='+ keyboards.qiwi_number +'¤cy=643&comment='+ komment +'&amountInteger='+ str(keyboards.tovar3price) +'&amountFraction=0&blocked%5B0%5D=account&blocked%5B1%5D=comment&blocked%5B2%5D=sum')) @bot.callback_query_handler(func=lambda message:True) def ans(message): chat_id = message.message.chat.id oplata = False if message.data == "check_oplata": c.execute("SELECT * FROM opl WHERE id = ('%s')"%(chat_id)) row = c.fetchone() comment = row[2] price = row[1] s = requests.Session() s.headers[u'authorization'] = u'Bearer ' + keyboards.qiwi_token parameters = {'rows': '28'} h = s.get(u'https://edge.****.com/payment-history/v1/persons/'+keyboards.qiwi_number+'/payments', params = parameters) req = json.loads(h.text) for i in range(len(req[u'data'])): suma = req['data'][i]['sum']['amount'] com = req['data'][i]['comment'] if (com == comment) and (int(price) == int(suma)): oplata = True c.execute("DELETE * FROM opl WHERE id = ('%s')"%(chat_id)) #тут ваши действия после оплаты break else: oplata = False if oplata == False: bot.send_message(chat_id, "❕ Платеж еще не дошел, повторите попытку позже", reply_markup=keyboards.oplata_keyboard('https://****.com/payment/form/99?extra%5B%27account%27%5D='+ keyboards.qiwi_number +'¤cy=643&comment='+ comment +'&amountInteger='+ price +'&amountFraction=0&blocked%5B0%5D=account&blocked%5B1%5D=comment&blocked%5B2%5D=sum')) elif message.data == "otmena_oplata": c.execute("SELECT * FROM opl WHERE id = ('%s')"%(chat_id)) bot.send_message(message.chat.id, " ", reply_markup=keyboards.main_keyboard()) elif message.data == "otmena_oplata": bot.send_message(message.chat.id, " ", reply_markup=keyboards.main_keyboard()) bot.polling(none_stop=True) keyboards.py import telebot from telebot import types import random import sqlite3 tovar1 = 'Товар 1' tovar1price = 10 tovar2 = 'Товар 2' tovar2price = 10 tovar3 = 'Товар 3' tovar3price = 10 chars = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' qiwi_number = '**** номер' qiwi_token = '**** токен' def main_keyboard(): markup= types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) catalog = types.KeyboardButton(' Каталог товаров') markup.add(catalog) markup.add(zakazi) return markup def list_keyboard(): markup= types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) tovarfirst = types.KeyboardButton(tovar1) tovarsecond = types.KeyboardButton(tovar2) tovarthird = types.KeyboardButton(tovar3) markup.add(tovarfirst) markup.add(tovarsecond) markup.add(tovarthird) return markup def oplata_keyboard(url1): markup = types.InlineKeyboardMarkup() oplatit = types.InlineKeyboardButton('Оплатить', url = url1) check = types.InlineKeyboardButton('Проверить оплату', callback_data="check_oplata") otmena = types.InlineKeyboardButton('Отменить оплату', callback_data="otmena_oplata") markup.add(oplatit) markup.add(check) markup.add(otmena) return markup def generate_komment(): for n in range(1): komment = '' for i in range(6): komment += random.choice(chars) return komment Код import telebot from telebot import types import random import sqlite3 tovar1 = 'Товар 1' tovar1price = 10 tovar2 = 'Товар 2' tovar2price = 10 tovar3 = 'Товар 3' tovar3price = 10 chars = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' qiwi_number = '**** номер' qiwi_token = '**** токен' def main_keyboard(): markup= types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) catalog = types.KeyboardButton(' Каталог товаров') markup.add(catalog) markup.add(zakazi) return markup def list_keyboard(): markup= types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True) tovarfirst = types.KeyboardButton(tovar1) tovarsecond = types.KeyboardButton(tovar2) tovarthird = types.KeyboardButton(tovar3) markup.add(tovarfirst) markup.add(tovarsecond) markup.add(tovarthird) return markup def oplata_keyboard(url1): markup = types.InlineKeyboardMarkup() oplatit = types.InlineKeyboardButton('Оплатить', url = url1) check = types.InlineKeyboardButton('Проверить оплату', callback_data="check_oplata") otmena = types.InlineKeyboardButton('Отменить оплату', callback_data="otmena_oplata") markup.add(oplatit) markup.add(check) markup.add(otmena) return markup def generate_komment(): for n in range(1): komment = '' for i in range(6): komment += random.choice(chars) return komment
infinityjq, Я видел, человек просто не понимает, что люди все разные и подход к работе тоже разный, особенно в программировании. Орнул я с него нормально. Посмотрел бы я на его бьютефолкод
sesu, Ты со своими парадигмами лучше молчи. Ты еще скажи, что каждый программист должен писать по полным стандартам PEP8
Очевидно паттерны использовать нужно! Вы поймите что хуже не станет, писать хороший код очень тяжело. К этому со временем приодишь, уже давно доказано что вот такая хуйня в коде это рак, это несет убытки, это тратит время.
sesu, тратят время только те, кто пиздят чужой код и пытаются в нем разобраться, а те, кто пишут код, пишут его для себя.
MindMayhem, баги зависят от уровня написания кода, если ты хуевый программист, как переменную не называй, все равно получится хуйня
MindMayhem, MindMayhem, Вы ебанутые, это ваш код или что? Вы супер невьебеные программисты? Так покажите мне ваш бьютефолкод. Чел выложил, чтоб люди, которым это надо, пользовались, а не чтоб такие дебилы обыграли код. Идите и нахуярте мне обычный калькулятор по всем стандартам PEP8
sesu, Он работает в крупной компании, чтоб код отлично читался? Ты ещё скажи чтоб он документацию к коду этому написал
ДА! И пусть тесты еще пишет интеграционные и юнит! Это понимаешь заповедь, этому необходимо следовать.
sesu, Блять, вот когда ему это надо будет, он и сделает. А когда код находится тут и сделан для того чтоб им пользоваться, ЗАХУЯ ТРАТИТЬ НА ЭТО ОВЕР ДОХУЯ ВРЕМЕНИ. Я тебе ещё раз скажу, напиши мне прогу по всем стандартам PEP8, если это у тебя получится, то так уж и быть, я отстану
sesu, PEP8 это стандарт(советы) по правильному написанию кода, раз ты такой умный и хороший кодер, то покажи мне, то что ты умеешь делать. Пока я вижу, что ты только своим говнортом умеешь болтать и выебываться. Ты мне покажи на деле, а не поносам из твоего рта