def find(self, quantity_id): one = self._conn.cursor() one.execute( "SELECT id,description,price,quantity From Products WHERE id = ({})" .format(quantity_id)) return Product(*one.fetchone())
def main(args): # imports import os # delete DataBase if exists if os.path.exists('moncafe.db'): os.remove('moncafe.db') from Repository import repo repo.create_tables() from DTO import Employee, Coffee_stand, Product, Supplier # with open('config.txt') as inputFile: # for line in inputFile: # print(line) inputfilename = args[1] with open(inputfilename) as inputfile: for line in inputfile: words = line.split(",") if words[0] == 'C': repo.coffee_stands.insert( Coffee_stand(words[1].strip(' '), words[2].strip(' '), words[3].strip(' '))) if words[0] == 'S': repo.suppliers.insert( Supplier(words[1].strip(' '), words[2].strip(' '), words[3][:-1].strip(' '))) if words[0] == 'E': repo.employees.insert( Employee(words[1].strip(' '), words[2].strip(' '), words[3].strip(' '), words[4].strip(' '))) if words[0] == 'P': repo.products.insert( Product(words[1].strip(' '), words[2].strip(' '), words[3].strip(' '), 0))
def find(self, id): cursor = self.conn.cursor() cursor.execute( """ SELECT * FROM Products WHERE id = ? """, ([id])) return Product(*cursor.fetchone())
def find_all(self): c = self._conn.cursor() all = c.execute(""" SELECT * FROM Products ORDER BY Products.id """).fetchall() return [Product(*row) for row in all]
def main(args): repo.create_tables() inputfilename = args[1] with open(inputfilename) as inputfile: for line in inputfile: line = line.strip('\n') args = line.split(', ') orginal2= args[2] orginal3 = args[3] args[1] = str(args[1]).replace(" ", "") args[2] = str(args[2]).replace(" ", "") args[3] = str(args[3]).replace(" ", "") if args[0] == "C": currCoffee_stand = Coffee_stand(args[1], "'{}'".format(args[2]), args[3]) repo.coffee_stands.insert(currCoffee_stand) if args[0] == "S": args[3] = orginal3 currSupplier = Supplier(args[1],"'{}'".format(args[2]),"'{}'".format(args[3])) repo.suppliers.insert(currSupplier) if args[0] == "E": args[4] = str(args[4]).replace(" ", "") currEmployee = Employee(args[1],args[2],args[3],args[4]) repo.employees.insert(currEmployee) if args[0] == "P": args[2]=orginal2 currProduct = Product(args[1], "'{}'".format(args[2]), args[3], 0) repo.products.insert(currProduct)
def find(self, product_id): c = self._conn.cursor() c.execute( """ SELECT *FROM Products WHERE id = ? """, [product_id]) return Product(*c.fetchone())
def find(self, id): c = self._conn.cursor() c.execute( """ SELECT id, description, price, quantity FROM Products WHERE id = ? """, [id]) return Product(*c.fetchone())
def get_sale_income(self, id): cur = self._conn.cursor() all = cur.execute(""" SELECT * FROM Activities """).fetchall() activity = [Activity(*row) for row in all] sum = 0 for act in activity: if act.quantity < 0: if act.activator_id == id: products_by_id = cur.execute(""" SELECT * FROM Products WHERE id = ({})""".format(act.product_id)) pro = Product(*products_by_id.fetchone()) sum = sum + (int(act.quantity) * -1 * float(pro.price)) return sum
def load_configuration(): config = sys.argv[1] # file_action = open(sys.argv[2]) file = open(config, 'r') content = file.read() lines = content.split("\n") for line in lines: p = line.split(", ") if p[0] == "E": repo.employee.insert(Employee(p[1], p[2], p[3], p[4])) if p[0] == "S": repo.supplier.insert(Supplier(p[1], p[2], p[3])) if p[0] == "P": repo.product.insert(Product(p[1], p[2], p[3], 0)) if p[0] == "C": repo.coffee_stand.insert(Coffee_stand(p[1], p[2], p[3]))
def main(): repo.create_table() with open(sys.argv[0], 'r') as config_file: for line in config_file: line = line.strip('\n') line = line.replace(' ', '').split(',') if line[0] == 'E': tmp = Employee(int(line[1]), line[2], float(line[3]), int(line[4])) repo.Employees.insert(tmp) if line[0] == 'S': tmp = Supplier(int(line[1]), line[2], line[3]) repo.Suppliers.insert(tmp) if line[0] == 'P': tmp = Product(int(line[1]), line[2], float(line[3])) repo.Products.insert(tmp) if line[0] == 'C': tmp = Coffee_stand(line[1], line[2], line[3]) repo.Coffee_stands.insert(tmp)
def insert_to_tables(): with open(sys.argv[1], "r") as file: for line in file: if line[-1] == '\n': line = line[:-1] lineList = line.split(', ') if lineList[0] == "C": coffee_stand = Coffee_stand(lineList[1], lineList[2], lineList[3]) repo.Coffee_stands.insert(coffee_stand) elif lineList[0] == 'S': supplier = Supplier(lineList[1], lineList[2], lineList[3]) repo.Suppliers.insert(supplier) elif lineList[0] == 'E': employee = Employee(lineList[1], lineList[2], lineList[3], lineList[4]) repo.Employees.insert(employee) elif lineList[0] == 'P': product = Product(lineList[1], lineList[2], lineList[3], 0) repo.Products.insert(product)
def main(args): repo.create_tables() inputfilename = args[1] with open(inputfilename) as inputfile: for line in inputfile: line.split(", ") if line[0]=="C": #print(line[:-1].split(", ")[1:]) repo.Coffee_stands.insert(Coffee_stand(*line.split(", ")[1:])) if line[0]=="E": #print(line[:-1].split(", ")[1:]) repo.Employees.insert(Employee(*line.split(", ")[1:])) if line[0]=="S": #print(line[:-1].split(", ")[1:]) repo.Suppliers.insert(Supplier(*line.split(", ")[1:])) if line[0]=="P": #print(line[:-1].split(", ")[1:].__add__(["0"])) repo.Products.insert(Product(*line.split(", ")[1:].__add__(["0"])))
def findAll(self): c = self._conn.cursor() all = c.execute("SELECT * FROM Products order by id ASC") return [Product(*row) for row in all]
def findQuantityById(self, id): c = self._conn.cursor() c.execute("SELECT * FROM Products where id=?", [id]) return Product(*c.fetchone()).quantity
def find_all(self): cursor = self.conn.cursor() all_stands = cursor.execute(""" SELECT * FROM Products C""").fetchall() return [Product(*row) for row in all_stands]