def callback_data_pre_order(bot, call): if call.data == "order_true": user = get_user_by_id(call.message.chat.id) date = datetime.datetime.now() date_id = re.search(r"[0-9]{4}-[0-9]{2}-[0-9]{2}", str(date)) date_id = date_id.group() cart = Cart(call.message.chat.id) params = catalog.pre_order_params new_order( call.message.chat.id, json.dumps({ "Chat ID": call.message.chat.id, "Phone": params["number"], "Name": user[1], "Username": user[2], }), cart.return_cart_json(), date_id, 0, json.dumps(params)) set_phone_number_to_user(call.message.chat.id, params["number"]) set_making_order_status_to_user(call.message.chat.id, 0) send_to_operators(bot, call.message) bot.send_message( call.message.chat.id, inscriptions.order_true.format( max(get_orders_ids_by_id(778508362))[0])) set_making_order_status_to_user(call.message.chat.id, 0) callback_clear_cart(call) elif call.data == "order_false": set_making_order_status_to_user(call.message.chat.id, 0) catalog.pre_order_params = None bot.send_message(call.message.chat.id, inscriptions.order_false)
def cart_update(bot, call): cart = Cart(call.message.chat.id) if cart.items == {}: bot.delete_message(call.message.chat.id, call.message.message_id) bot.send_message(call.message.chat.id, inscriptions.cart_is_empty, parse_mode='html')
def how_many_in_cart(chat_id, products, current_prod_catalog): cart = Cart(chat_id) products_in_cart = cart.items try: cur_prod_amount = products_in_cart[str( products[current_prod_catalog][0])][7]["amount"] cur_prod_amount_string = f"({cur_prod_amount}) " return cur_prod_amount_string except TypeError: return "" except KeyError: return ""
def checking_order_creating_steps(bot, message, types, steps, params): if not steps["number_of_departament"]: bot.send_message(message.chat.id, inscriptions.number_of_departament) params["city"] = message.text steps["number_of_departament"] = True elif not steps["full_name"]: bot.send_message(message.chat.id, inscriptions.full_name) params["number_of_departament"] = message.text steps["full_name"] = True elif not steps["number"]: bot.send_message(message.chat.id, inscriptions.number) params["full_name"] = message.text steps["number"] = True elif not steps["payment_system"]: bot.send_message(message.chat.id, inscriptions.payment_system, parse_mode='html') params["number"] = message.text steps["payment_system"] = True else: params["payment_system"] = message.text cart = Cart(message.chat.id) catalog.set_pre_order_params(params) markup = create_pre_order_markup(types) items_arr = make_items_array(message) items_text = items_arr[0] result_sum = items_arr[1] params_text = "" for k in params: params_text += "<b>{0}: </b>{1}\n".format( inscriptions.params_text[k], params[k]) bot.send_message( message.chat.id, "{1}\n\n---\n{0}".format(items_text, inscriptions.is_everything_right) + "---\n\n{1}<b>Итого: </b>{0}".format(result_sum, params_text) + inscriptions.currency, parse_mode='html', reply_markup=markup) cart.pre_order_params = params
def make_items_array(message): cart = Cart(message.chat.id) items = cart.items items_arr = list() items_text = str() items_sum = 0 try: for item in items: amount = items[item][7]['amount'] price = items[item][3] local_sum = amount * price items_text += f"<b>{items[item][1]}</b>\n{amount} " \ f"{inscriptions.amount} x {price}{inscriptions.currency} = {local_sum}\n" items_sum += local_sum if items_text == "": return None else: items_arr.append(items_text) items_arr.append(items_sum) return items_arr except TypeError: return None
def callback_clear_cart(call): cart = Cart(call.message.chat.id) cart.items = None cart.set_cart_to_user()
def callback_to_cart(call): cart = Cart(call.message.chat.id) cart.add_item(catalog.products[catalog.current_prod]) cart.set_cart_to_user()
from classes.logger import Logger from classes.cart import Cart from classes.captcha import Captcha from classes.queue import Queue from classes.tools import Tools if __name__ == '__main__': session = requests.Session() lock = threading.Lock() tools = Tools() config = tools.load('config/config.json') log = Logger().log q = Queue() cart = Cart(session, lock) api_key = config['key']['2captcha'] captcha = Captcha(api_key) queue = Queue() if 'true' in config['settings']['browser']['US'].lower() and 'true' in config['settings']['browser']['EU'].lower(): log('You have both regions selected - please select only one.','error') exit() if 'true' in str(config['settings']['captcha'].lower()): captcha.harvest(queue) log('Initializing script..','info') ''' cart.add_to_cart(['zollar','jacket','ice'],'medium') cart.add_to_cart(['zollar','jacket','gold'],'small')
import requests import time import threading import json from classes.logger import Logger from classes.cart import Cart from classes.tools import Tools if __name__ == '__main__': session = requests.Session() lock = threading.Lock() tools = Tools() config = tools.load('config/config.json') log = Logger().log cart = Cart(session, lock) log('Initializing script..', 'info') # Small, Medium, Large, one size t1 = threading.Thread(target=cart.add_to_cart, args=(['kith', 'classic', 'tee', 'logo', 'blue'], ['s', 'l'])) t1.start() #t2.start() #t3.start() t1.join() #t2.join() #t3.join()