def after_callback(message, call=False): send = bot.send_message( message.chat.id, "I am very glad that you are not ready to give up!\n\n Ok send me the number you think. \n\n\nSRN 🧬: {srn}\nSEN 🧫: {sen}\nSTN 🦠: {s_t_n}" .format(srn=db.get_product(call.from_user.id, True, False, False), s_t_n=db.get_product(call.from_user.id, False, False, True), sen=db.get_product(call.from_user.id, False, True, False))) bot.register_next_step_handler(send, update_message)
def view_bought_products(self): prod_objects = [] pb = database.get_prods_bought(self) for prod_id in pb: prod_objects.append(database.get_product(prod_id)) products = self.get_products_details(prod_objects) max_len = 0 first = True prod_keys = [] for prod in products: if first: prod_keys = list(prod.keys()) first = False for key in prod: if len(key) > max_len: max_len = len(str(key)) if len(str(prod[key])) > max_len: max_len = len(str(prod[key])) format_string = "{:<" + str(max_len + 5) + "}" print() for key in prod_keys: print(format_string.format(key), end="") print() for prod in products: for key in prod: value = prod[key] print(format_string.format(value), end="") print()
def addtocart(): code = request.args.get('code', '') product = db.get_product(int(code)) item=dict() # A click to add a product translates to a quantity of 1 item["qty"] = 1 item["name"] = product["name"] item["subtotal"] = product["price"]*item["qty"]
def get_post(post_id): post_info = database.get_post(post_id) product_info = database.get_product(post_id) image_info = database.get_image(post_id) result = json.loads(post_info) result[0]["products"] = product_info result[0]["images"] = image_info print(str(result[0])) return json.dumps(result[0])
def handle_json_protocol(self): # still debug stuff here json_data = self.read_json() try: (request_type, obj) = json_protocol.parse_json_request(json_data) if request_type is json_protocol.RequestType.IDENTIFY: products = [] img_datas = obj for img_data in img_datas: possible_matches = self.image_processor.match_image( img_data) print(possible_matches) if possible_matches: best_metashop_id = possible_matches[0][0] db_result = database.get_product( best_metashop_id )[:-2] # Don't need pricing information image_filename = config.IMAGES_DIR + '/' + image_util.get_full_filename( config.IMAGES_DIR, str(best_metashop_id)) image = image_util.load_image_bytes(image_filename) db_result.append(image) temp = db_result[0] db_result[0] = db_result[1] db_result[1] = temp products.append(db_result) else: products.append([ 'INVALID PRODUCT', '-1', '-1', '-1', INVALID_IMAGE ]) response = json_protocol.build_json_response( json_protocol.ResponseType.IDENTIFY, products) self.send_json(response) elif request_type is json_protocol.RequestType.PRICE_CHECK: metashop_ids = [int(metashop_id) for metashop_id in obj] products = database.get_products(metashop_ids) walmart_skus = [] for product in products: walmart_skus.append(product[2]) walmart_prices = retailer_lookup.lookup_walmart_prices( walmart_skus) prices = [] for walmart_price in walmart_prices: prices.append([walmart_price, -1.0]) response = json_protocol.build_json_response( json_protocol.ResponseType.PRICE_CHECK, prices) self.send_json(response) except binascii.Error as ex: self.send_json( json_protocol.build_json_response( json_protocol.ResponseType.ERROR, str(ex))) except RuntimeError as ex: self.send_json( json_protocol.build_json_response( json_protocol.ResponseType.ERROR, str(ex)))
def get_customer_menu(customer_obj, cart_obj): print() print("1. View products") print("2. Buy product") print("3. Add product to cart") print("4. Delete product from cart") print("5. View cart") print("6. Buy products in cart") print("7. View bought products") print("8. Exit") opt = int(input("Enter the appropriate number : ")) while opt != 8: if opt == 1: view_products(customer_obj) elif opt == 2: buy_product(customer_obj) elif opt == 3: product_id = int(input("Enter the ID of the product to add : ")) prod_obj = database.get_product(product_id) customer_obj.add_to_cart(cart_obj, prod_obj) elif opt == 4: product_id = int(input("Enter the ID of the product to delete : ")) prod_obj = database.get_product(product_id) customer_obj.delete_from_cart(cart_obj, prod_obj) elif opt == 5: view_cart(customer_obj, cart_obj) elif opt == 6: buy_cart(customer_obj, cart_obj) elif opt == 7: customer_obj.view_bought_products() elif opt != 8: print("Invalid option! Try again") print() print("1. View products") print("2. Buy product") print("3. Add product to cart") print("4. Delete product from cart") print("5. View cart") print("6. Buy products in cart") print("7. View bought products") print("8. Exit") opt = int(input("Enter the appropriate number : "))
def get_all_products_details(self): product_ids = database.get_product_ids() results = [] for i in product_ids: product_obj = database.get_product(i) result_obj = dict() result_obj["ID"] = product_obj.get_id() result_obj["NAME"] = product_obj.get_name() result_obj["PRICE"] = product_obj.get_price() result_obj["GROUP"] = product_obj.get_group() result_obj["SUBGROUP"] = product_obj.get_subgroup() results.append(result_obj) return results
def updatecart(): cart = session["cart"] code = request.form.get('code') qty = int(request.form.get('qty')) unit_price = request.form.get('price') product = db.get_product(int(code)) for item in cart.values(): if item["code"] == code: item["qty"] = qty item["subtotal"] = product["price"] * qty cart[code] = item session["cart"] = cart return render_template("cart.html")
def settings(message): Home = types.ReplyKeyboardMarkup() home = types.InlineKeyboardButton('Home 🏠') solo = types.InlineKeyboardButton('Solo game 🧐') multiplayer = types.InlineKeyboardButton('Play with friend 👨👦👦') Home.add(home) Home.add(solo, multiplayer) user = db.get_info(message.from_user.id) send = bot.send_message( message.chat.id, 'Your settings ⚙️: \n\nId 👊: {id}\nUsername 🤙: {un}\nName 👨🦰: {name}\n\n\nMoney 💶: {money}\n\n\nTotal win 🏆: {win}\nTotal number of games played 🎮: {tg} \n\n\nSRN 🧬: {srn}\nSEN 🧫: {sen}\nSTN 🦠: {s_t_n}\n\n\n If you wont back to home click on button below. ⬇️⬇️⬇️' .format(id=message.from_user.id, un=message.from_user.username if message.from_user.username != None else 'you haven`t username', name=message.from_user.first_name, money=user[3], win=user[4], tg=user[5], srn=db.get_product(message.from_user.id, True, False, False), s_t_n=db.get_product(message.from_user.id, False, False, True), sen=db.get_product(message.from_user.id, False, True, False)), reply_markup=Home) bot.register_next_step_handler(send, update_message)
def updatecart(): code = request.form.getlist("code") qty = request.form.getlist("qty") cart = session["cart"] for item in range(len(code)): product = db.get_product(int(code[item])) cart[code[item]]["qty"] = int(qty[item]) cart[code[item]]["subtotal"] = int(qty[item]) * int(product["price"]) session["cart"] = cart return redirect('/cart')
def form_submission(): code = request.form.getlist("code") qty = request.form.getlist("qty") cart = session["cart"] for i in range(len(code)): product = db.get_product(int(code[i])) cart[code[i]]["qty"] = int(qty[i]) cart[code[i]]["subtotal"] = int(qty[i]) * product["price"] session["cart"] = cart return redirect('/cart')
def add9tocart(): code = request.args.get('code', '') product = db.get_product(int(code)) item = dict() item["qty"] = 9 item["name"] = product["name"] item["subtotal"] = product["price"] * item["qty"] if (session.get("cart") is None): session["cart"] = {} cart = session["cart"] cart[code] = item session["cart"] = cart return redirect('/cart')
def addtocart(): code = request.args.get('code', '') product = db.get_product(int(code)) item = dict() # A click to add a product translates to a quantity of 1 item["qty"] = 1 item["name"] = product["name"] item["subtotal"] = product["price"] * item["qty"] if (session.get("cart") is None): session["cart"] = {} cart = session["cart"] cart[code] = item session["cart"] = cart return redirect('/cart')
def updateqty(): stype = request.args.get("stype") code = request.args.get('code', '') product = db.get_product(int(code)) cart = session["cart"] print(cart) if stype == "+": cart[code]['qty'] += 1 cart[code]['subtotal'] = product["price"] * cart[code]["qty"] else: if cart[code]["qty"] > 1: cart[code]["qty"] -= 1 cart[code]['subtotal'] = product["price"] * cart[code]["qty"] session["cart"] = cart return redirect('/cart')
def addtocart(): code = request.form.get('code') quantity = int(request.form.get('quantity')) product = db.get_product(int(code)) item=dict() # A click to add a product translates to a quantity of 1 for now, creating a temporary dictionary item["qty"] = quantity item["code"] = code item["name"] = product["name"] item["subtotal"] = product["price"]*item["qty"] if(session.get("cart") is None): session["cart"]={} cart = session["cart"] cart[code]=item session["cart"]=cart return redirect('/cart')
def addtocart(): code = request.form.get('code') quantity = int(request.form.get('quantity')) product = db.get_product(int(code)) item = dict() item["qty"] = quantity item["code"] = code item["name"] = product["name"] item["subtotal"] = product["price"] * item["qty"] if (session.get("cart") is None): session["cart"] = {} cart = session["cart"] cart[code] = item session["cart"] = cart return redirect('/cart')
def updatecart(): request_type = request.form.get('submit') code = request.form.get('code') product = db.get_product(int(code)) cart = session["cart"] if request_type == "Update": quantity = int(request.form.get("quantity")) cart[code]["qty"] = quantity cart[code]["subtotal"] = quantity * product["price"] elif request_type == 'Remove': del cart[code] session["cart"] = cart return redirect('/cart')
def remove(): code = request.form.get('code', '') product = db.get_product(int(code)) qty = request.form.get('reset', '') item = dict() item["code"] = code item["qty"] = int(qty) item["name"] = product["name"] item["price"] = product["price"] item["subtotal"] = product["price"] * item["qty"] if (session.get("cart") is None): session["cart"] = {} cart = session["cart"] cart[code] = item session["cart"] = cart return redirect('/cart')
def buy_product(customer_obj): view_products(customer_obj) print() product_id = int(input("Enter the id of the product to buy : ")) product_obj = database.get_product(product_id) if product_obj is None: print("Enter a valid product ID!") return quantity = int(input("Enter the quantity : ")) price = product_obj.get_price() * quantity print("Total price to be paid " + str(price)) print() print("PAYMENT DETAILS") card_type = input("Enter card type : ") card_num = input("Enter card number : ") payment_obj = Payment(customer_obj.get_id(), price, card_type, card_num) success = customer_obj.buy_product(product_obj, payment_obj, quantity) if success: print("Shipment successfully initiated. Payment reference ID = " + str(payment_obj.get_id())) else: print("Some problem occurred while transaction")
def modify_product(self, prod_id, attribute_name, modified_value): prod_obj = database.get_product(prod_id) prod_obj.modify_product(attribute_name, modified_value)
def productdetails(): code = request.args.get('code', '') product = db.get_product(int(code)) return render_template('productdetails.html', code=code, product=product)
def products(): product_list = db.get_product() return render_template('products.html', page="Products", product_list=product_list)
def view_all_products(self): product_ids = database.get_product_ids() for i in product_ids: product_obj = database.get_product(i) print(product_obj.get_string())
def api_get_product(code): resp = make_response(dumps(db.get_product(code))) resp.mimetype = 'application/json' return resp
def solo_before_update(message, call=False): if call == False: Supernum = types.InlineKeyboardMarkup() SRN = types.InlineKeyboardButton('Use SRN 🧬', callback_data='use_srn') SEN = types.InlineKeyboardButton('Use SEN 🧫', callback_data='use_sen') STN = types.InlineKeyboardButton('Use STN 🦠', callback_data='use_stn') Supernum.add(SRN) Supernum.add(SEN) Supernum.add(STN) num = s_db.get_num(message.from_user.id) num_player = message.text get_result = sn.get_result(message.from_user.id) if num_player.isdigit() and len(str(num_player)) == len( str(num)) and get_result != '????': silver, gold = n_u.get_bull(str(num), str(num_player)) if gold == int(len(str(num))): s_db.play(message.from_user.id, False) db.win(message.from_user.id) sn.drop_num(message.from_user.id) bot.send_message( message.chat.id, 'Yeah! You win! \n\nMy nomber is {num}'.format(num=num)) sey_hello(message, False) else: sent = bot.send_message( message.chat.id, 'Oh no!\n\n You don\'t get it. Please try again. \n \n You have that kind of data coming out of that number: \n\n Silver - {silver} \n Gold - {gold} \n\nSuper Number - {result}\n\n\nSRN 🧬: {srn}\nSEN 🧫: {sen}\nSTN 🦠: {s_t_n}\n\n\nI wait next number =)' .format(silver=silver, gold=gold, result=sn.get_result(message.from_user.id), srn=db.get_product(message.from_user.id, True, False, False), s_t_n=db.get_product(message.from_user.id, False, False, True), sen=db.get_product(message.from_user.id, False, True, False)), reply_markup=Supernum) bot.register_next_step_handler(sent, update_message) else: sent = bot.send_message( message.chat.id, 'Mate, please send me correct four-digit number! \n\n Example: {}' .format(randint(1000, 9999))) bot.register_next_step_handler(sent, update_message) else: Supernum = types.InlineKeyboardMarkup() SRN = types.InlineKeyboardButton('Use SRN 🧬', callback_data='use_srn') SEN = types.InlineKeyboardButton('Use SEN 🧫', callback_data='use_sen') STN = types.InlineKeyboardButton('Use STN 🦠', callback_data='use_stn') Supernum.add(SRN) Supernum.add(SEN) Supernum.add(STN) num = s_db.get_num(call.from_user.id) num_player = message.text if num_player.isdigit() and len(str(num_player)) == len(str(num)): silver, gold = n_u.get_bull(str(num), str(num_player)) if gold == int(len(str(num))): s_db.play(call.from_user.id, False) db.win(call.from_user.id) sn.drop_num(call.from_user.id) bot.send_message( message.chat.id, 'Yeah! You win! \n\nMy nomber is {num}'.format(num=num)) sey_hello(message, False) else: sent = bot.send_message( message.chat.id, 'Oh no!\n\n You don\'t get it. Please try again. \n \n You have that kind of data coming out of that number: \n\n Silver - {silver} \n Gold - {gold} \n\nSuper Number - {result}\n\n\nSRN 🧬: {srn}\nSEN 🧫: {sen}\nSTN 🦠: {s_t_n}\n\n\nI wait next number =)' .format(silver=silver, gold=gold, result=sn.get_result(call.from_user.id), srn=db.get_product(call.from_user.id, True, False, False), s_t_n=db.get_product(call.from_user.id, False, False, True), sen=db.get_product(call.from_user.id, False, True, False)), reply_markup=Supernum) bot.register_next_step_handler(sent, update_message) else: sent = bot.send_message( message.chat.id, 'Mate, please send me correct four-digit number! \n\n Example: {}' .format(randint(0000, 9999))) bot.register_next_step_handler(sent, update_message)
def call_update(call): if call.data: if call.data == 'yes': bot.send_message( call.message.chat.id, 'You lose! 😩\n\n My number was:{}'.format( s_db.get_num(call.from_user.id))) s_db.play(call.from_user.id, False) sn.drop_num(call.from_user.id) sey_hello(call.message, call) elif call.data == 'no': after_callback(call.message, call) elif call.data == 'SRN': buy_product(call.message, call.from_user.id, 35, 'srn') elif call.data == 'SEN': buy_product(call.message, call.from_user.id, 100, 'sen') elif call.data == 'STN': buy_product(call.message, call.from_user.id, 360, 'stn') elif call.data == 'yes_buy': shop_nick(call.message) elif call.data == 'no_buy': sey_hello(call.message, call) elif call.data == 'bth': sey_hello(call.message, call) elif call.data == 'use_srn': Supernum = types.InlineKeyboardMarkup() SRN = types.InlineKeyboardButton('Use SRN 🧬', callback_data='use_srn') SEN = types.InlineKeyboardButton('Use SEN 🧫', callback_data='use_sen') STN = types.InlineKeyboardButton('Use STN 🦠', callback_data='use_stn') Supernum.add(SRN) Supernum.add(SEN) Supernum.add(STN) if db.get_product(call.from_user.id, True, True, False) >= 1: random = randint(1, 4) num = s_db.get_num(call.from_user.id) number = sn.run_srn(call.from_user.id, random, num) db.use_product(call.from_user.id, True, False, False) call.data = '' bot.send_message( call.message.chat.id, 'Success! 🎉🎉🎉\n\n I choose the {} number, and he turned out is {}! 😳\n\n So, now you have this result: {} ⬅️\n\n\nI wait next number =)' .format(random, number, sn.get_result(call.from_user.id)), reply_markup=Supernum) else: call.data = '' bot.send_message( call.message.chat.id, 'You haven`t supernumber! \n\n\nSRN 🧬: {srn}\nSEN 🧫: {sen}\nSTN 🦠: {s_t_n}' .format(srn=db.get_product(call.from_user.id, True, False, False), s_t_n=db.get_product(call.from_user.id, False, False, True), sen=db.get_product(call.from_user.id, False, True, False))) solo_before_update(call.message, call) elif call.data == 'use_sen': if db.get_product(call.from_user.id, False, True, False) >= 1: db.use_product(call.from_user.id, False, True, False) call.data = '' run = randint(1000, 9999) index = randint(1, 4) indexx = int(index) - 1 send = bot.send_message( call.message.chat.id, 'Ok, send me the number you want to know\n\nFor example: \n{} \nI want to find out the number :{} -> {}' .format(run, index, str(run)[indexx])) bot.register_next_step_handler(send, use_sen) else: print('sen', db.get_product(call.from_user.id, False, True, False)) call.data = '' bot.send_message( call.message.chat.id, 'You haven`t supernumber! \n\n\nSRN 🧬: {srn}\nSEN 🧫: {sen}\nSTN 🦠: {s_t_n}' .format(srn=db.get_product(call.from_user.id, True, False, False), s_t_n=db.get_product(call.from_user.id, False, True, True), sen=db.get_product(call.from_user.id, False, True, True))) solo_before_update(call.message, call)