def create_product(): request_data = request.get_json() product_data = dict(name=request_data.get('prodname'), category=request_data.get('category'), quantity=request_data.get('quantity')) product = Products(**product_data) product.store() return HTTPStatus.CREATED
def post(self): data = request.get_json() if data is not None: session = Session() totalPrice = float(data['price']) * float(data['quantity']) product = Products(productName=data['name'], prductQuantity=int(data['quantity']), productCategory=data['category'].lower(), prodcutSinglePrice=float(data['price']), procuctTotalPrice=totalPrice) session.add(product) inventoryExists = session.query(Inventory).filter_by( categoryName=data['category'].lower()).first() if inventoryExists is not None: inventoryExists.categoryQuantity += int(data['quantity']) inventoryExists.categoryTotalAmount += float(totalPrice) else: inventory = Inventory(categoryName=data['category'].lower(), categoryQuantity=int(data['quantity']), categoryTotalAmount=totalPrice) session.add(inventory) session.commit() session.close() return Response('Added', status=201) else: return Response('False', status=500)
def retrieve_product(product_id): product = Products.load(id=product_id) if not product: return jsonify({'error': 'Product not found.'}), HTTPStatus.BAD_REQUEST response_data = { 'id': product.id, 'prodname': product.name, 'category': product.category, 'quantity': product.quantity, } return response_data, HTTPStatus.OK
def get_products(): products = Products.all() response_data = [] for product in products: d = { 'id': product.id, 'prodname': product.name, 'category': product.category, 'quantity': product.quantity, } response_data.append(d) return jsonify(response_data), HTTPStatus.OK
def get_data(pages): # for i in pages: # r=requests.get(i) time = datetime.now() r = requests.get(pages) #soup=BeautifulSoup(r.text,'lxml') soup = BeautifulSoup(r.text, 'html.parser') ads_block = soup.find('div', class_='product-grid category-products').find_all( 'div', class_='tile-box') for ad in ads_block: brand = ad.find('span', class_='brand-name').text.strip() name = ad.find('div', class_='h2').text.strip() price = ad.find('span', class_='price').text.replace('грн', '').split() price1 = ''.join(price) #print(int(price1)) img = ad.find('div', class_='product-image').a.img['data-src'].strip() text = ad.find('span', class_='product-type').text.strip() aromat = 'Древесный' Authors = 'deft' userId = 1 characteristics = 'characteristic characteristics characteristics characteristics characteristics characteristics scharacteristics' items = Products(brand=brand, Authors=Authors, name=name, price=int(price1), content=text, characteristics=characteristics, creationData=time, user_id=userId, img1=img, aromat=aromat) db.session.add(items) db.session.commit()
db.create_all() customer_1 = Customers(name='Iwan Moreton', email='*****@*****.**', house_number=2, postcode='BB5 5BU') customer_2 = Customers(name='First Last', email='*****@*****.**', house_number=2, postcode='BB5 5BU') db.session.add(customer_1) db.session.add(customer_2) db.session.commit() product_1 = Products(title='Game 1', price=32.50, stock=1) product_2 = Products(title='Game 2', price=35, stock=2) db.session.add(product_1) db.session.add(product_2) db.session.commit() order_1 = Orders( customer_id=Customers.query.filter_by(name='Iwan Moreton').first().id, product_id=Products.query.filter_by(title='Game 1').first().id) order_2 = Orders( customer_id=Customers.query.filter_by(name='Iwan Moreton').first().id, product_id=Products.query.filter_by(title='Game 2').first().id) order_3 = Orders( customer_id=Customers.query.filter_by(name='First Last').first().id,
from app import db, Orders, Customers, Products db.drop_all() db.create_all() ben = Customers(name='Ben', email='*****@*****.**') phone = Products(name='Samsung 7', price=250.00) db.session.add(ben) db.session.add(phone) db.session.commit() order_phone = Orders(product_id=phone.id, customer_id=ben.id) db.session.add(order_phone) db.session.commit()
from app import db, Orders, Customers, Products db.create_all() ben = Customers(name='Ben', email='*****@*****.**') phone = Products(name='iPhone 12 Pro', price=1049.00) db.session.add(ben) db.session.add(phone) db.session.commit() order_phone = Orders(product_id=phone.id, customer_id=ben.id) db.session.add(order_phone) db.session.commit()
from app import db, Customers, Products, Orders db.drop_all() db.create_all() customer_one = Customers(name="Dave", email="*****@*****.**") customer_two = Customers(name="Tom", email="*****@*****.**") product_one = Products(name="Laptop", price=499.99) product_two = Products(name="tabletennis table", price=125.99) order_one = Orders(customer=customer_one, product=product_one) order_two = Orders(customer=customer_one, product=product_two) order_three = Orders(customer=customer_two, product=product_one) db.session.add(customer_one) db.session.add(customer_two) db.session.add(product_one) db.session.add(product_two) db.session.add(order_one) db.session.add(order_two) db.session.add(order_three) db.session.commit()
from app import db, Customers, Products, Orders db.create_all() # Creates all table classes defined customer_1 = Customers( name='Kiran', email='*****@*****.**', ) phone1 = Products(name='OnePlus 6t', price=399.99) db.session.add(customer_1) db.session.add(phone1) db.session.commit()
from app import db, Customers, Products, Orders db.drop_all() db.create_all() # Creates all table classes defined customer_one = Customers(name="Abhyas", email='*****@*****.**') customer_two = Customers(name="Frank", email="*****@*****.**") product_one = Products(name="Laptop", price=499.99) product_two = Products(name="Rickenbacker 4003", price=2300.0) order_one = Orders(customer=customer_one, product=product_one) order_one = Orders(customer=customer_one, product=product_two) order_three = Orders(customer=customer_two, product=product_one) db.session.add(customer_one) db.session.add(customer_two) db.session.add(product_one) db.session.add(product_two) db.session.add(order_one) db.session.add(order_two) db.session.add(order_three) db.session.commit()