Exemplo n.º 1
0
 def creation():
     """ create all the tables by calling static method from these tables
     six tables including two association tables:
     - CategoryProduct and StoreProduct ."""
     with Connection.get_instance() as cursor:
         sql = """ CREATE DATABASE IF NOT EXISTS openfoodbase CHARACTER SET utf8; """
         cursor.execute(sql)
     Category.create()
     Product.create()
     Store.create()
     CategoryProduct.create()
     StoreProduct.create()
     Historic.create()
Exemplo n.º 2
0
def addDummyData():
    try:
        tempData = createDummyData()
        for user_id, product_id, rating in tempData:
            User.create(user_id, "*****@*****.**", product_id)
            Product.create(product_id, '10')
            Rating.create(user_id, product_id, rating)
        # add more records
        for user_id in range(20, 25):
            User.create(user_id, '*****@*****.**', '12')
            Rating.create(user_id, '12', random.randint(0, 5))
        return "dummy Data has been created", 200
    except Exception as e:
        print(e)
        return "exception while adding data, check the logs", 403
Exemplo n.º 3
0
def data_init():
    """Function that creates the different tables
    """
    # Create Category table (SQL REQUEST)
    categorie = Category()
    product = Product()
    favorite = Favorite()
    tables = {
        'Category': categorie.create(),
        'Product': product.create(),
        'Favorite': favorite.create()
    }
    # Create all tables of database
    for table_name in tables:
        table_description = tables[table_name]
        try:
            print(f"Création de la table {table_name} : ", end='')
            my_cursor.execute(table_description)
        except mysql.connector.Error as err:
            if err.errno == errorcode.ER_TABLE_EXISTS_ERROR:
                print("existe déjà.")
            else:
                print(err.msg)
        else:

            print("OK")

    # Insert 7 categories in my category table(manually)
    categorie.insert_data()
    # The categories of my table
    category_index = list()
    for item in data_categories:
        category_index.append(item[1])

        # browse categories and insert data
    for index in enumerate(category_index):
        # Upload json file from api
        data_for_insert = upload_data(index[1], 1)
        # Insert data in Product table
        size = len(data_for_insert['products'])
        print(f'{index[1]} - produits: {size}')

        # The loop that inserts the data into my tables
        for i in range(size):
            try:
                store = data_for_insert['products'][i]['stores']
                name = data_for_insert['products'][i]['product_name']
                grade = data_for_insert['products'][i][
                    'nutrition_grades_tags'][0]
                url = data_for_insert['products'][i]['url']
                id_category = index[0] + 1
            except (KeyError, TypeError):
                continue
            finally:
                product.insert_data(name, url, grade, id_category, store)
Exemplo n.º 4
0
from platin.core.date import Date
from zuoraobject import ZuoraObject

class ProductRatePlan(ZuoraObject):
    class_name = 'ProductRatePlan'
    
if __name__=="__main__":
    from product import Product
    from zuora.client import Zuora
    client = Zuora()
    p = Product('Auto - test')
    p.create(client)
    pr = ProductRatePlan('Product Rate 1',ProductId=p.id())
    pr.create(client)
Exemplo n.º 5
0
 def create():
     Purchase.create()
     Product.create()
     Purchase_product.create()
     Store.create()
Exemplo n.º 6
0
from platin.core.date import Date
from zuoraobject import ZuoraObject


class ProductRatePlan(ZuoraObject):
    class_name = 'ProductRatePlan'


if __name__ == "__main__":
    from product import Product
    from zuora.client import Zuora
    client = Zuora()
    p = Product('Auto - test')
    p.create(client)
    pr = ProductRatePlan('Product Rate 1', ProductId=p.id())
    pr.create(client)