async def create_product(product: schemas.productSchema, db: Session = Depends(get_db)): product_info = crud.create_product(db, product) if product_info: return JSONResponse( status_code=200, content={"message": f"the product was correctly saved"}) else: return JSONResponse(status_code=500, content={"message": f"Something Happened"})
async def create_product(product: schemas.ProductsCreate, db: Session = Depends(get_db)): return crud.create_product(db=db, product=product)
import os import json from random import choice, randint import crud import model import server os.system('dropdb products') os.system('createdb products') model.connect_to_db(server.app) model.db.create_all() # Load product data from JSON file with open('data/products.json') as f: product_data = json.loads(f.read()) # Create products, store them in list products_in_db = [] for product in product_data: brand, name, category, tag, img_path = (product['brand'], product['name'], product['category'], product['tag'], product['img_path']) db_product = crud.create_product(brand, name, category, tag, img_path) products_in_db.append(db_product)
import server os.system('dropdb web_commerce') os.system('createdb web_commerce') model.connect_to_db(server.app) model.db.create_all() # Create product table's initial data. with open('data/product.json') as f: product_data = json.loads(f.read()) product_in_db = [] for product in product_data: channel_name, product_description, option, product_url, price, added_on, number_sold, margin, updated_on = ( product['channel_name'], product['product_description'], product['option'], product['product_url'], product['price'], product['added_on'], product['number_sold'], product['margin'], product['updated_on']) db_product = crud.create_product(channel_name, product_description, option, product_url, price, added_on, number_sold, margin, updated_on) product_in_db.append(db_product)
with open('data/chemicals-in-cosmetics-data.tsv') as tsv_f: f = csv.reader(tsv_f, delimiter="\t") count = 1 for line in f: print('*******************************') print(count) print(line) print('*******************************') # line = line.rstrip() name, brand, product_categorization, ingredient_name = line product = crud.get_product_by_name(name) if product == None: product = crud.create_product( name=name, brand=brand, product_categorization=product_categorization) print('*******************************') print(product) print('*******************************') # product = crud.get_product_id(product_id) # if product == None: # product = crud.create_product(product_id) # print('*******************************') # print(product) # print('*******************************') ingredient = crud.get_ingredient_by_name(ingredient_name) if ingredient == None: ingredient = crud.create_ingredient(ingredient_name)