Ejemplo n.º 1
0
def read_suppliers(x, f):
    for i in range(x):
        s = f.readline()
        parser = s[0:-1].split(',')
        supplier_id = int(parser[0])
        name = parser[1]
        suppliers.append(name)
        logistic = int(parser[2])
        add_supplier(DTO.Supplier(supplier_id, name, logistic))
Ejemplo n.º 2
0
    def create_tables(self, path):
        self._conn.executescript("""
                CREATE TABLE Employees(
                    id INTEGER PRIMARY KEY, 
                    name TEXT NOT NULL,
                    salary REAL NOT NULL,
                    coffee_stand INTEGER REFERENCES Coffee_stands(id)        
                 );

                 CREATE TABLE Suppliers(
                    id INTEGER PRIMARY KEY,
                    name TEXT NOT NULL,
                    contact_information TEXT
                 );

                 CREATE TABLE Products(
                    id INTEGER PRIMARY KEY,
                    description TEXT NOT NULL,
                    price REAL NOT NULL,
                    quantity INTEGER NOT NULL
                 );

                 CREATE TABLE Coffee_stands(
                    id INTEGER PRIMARY KEY,
                    location TEXT NOT NULL,
                    number_of_employees INTEGER
                 );

                 CREATE TABLE Activities(
                    product_id INTEGER REFERENCES Products(id),
                    quantity INTEGER NOT NULL,
                    activator_id INTEGER NOT NULL,
                    date DATE NOT NULL
                 );
            """)

        text = open(path).readlines()
        for line in text:
            line = line.split(', ')
            for element in range(0, line.__len__()):
                line[element] = str(line[element]).replace("\n", '')

            if (line[0] == "C"):
                coffee_stand = DTO.Coffee_stand(int(line[1]), line[2],
                                                int(line[3]))
                self.coffee_stands.insert(coffee_stand)
            elif (line[0] == "S"):
                supplier = DTO.Supplier(int(line[1]), line[2], line[3])
                self.suppliers.insert(supplier)
            elif (line[0] == "E"):
                employee = DTO.Employee(int(line[1]), line[2], float(line[3]),
                                        int(line[4]))
                self.employees.insert(employee)
            elif (line[0] == "P"):
                product = DTO.Product(int(line[1]), line[2], float(line[3]), 0)
                self.products.insert(product)
Ejemplo n.º 3
0
def enter(entry, repo):
    if entry[0] == 'C':
        repo.coffeeStands.insert(DTO.CoffeeStand(entry[1], entry[2], entry[3]))
    elif entry[0] == 'E':
        repo.employees.insert(
            DTO.Employee(entry[1], entry[2], entry[3], entry[4]))
    elif entry[0] == 'P':
        repo.products.insert(DTO.Product(entry[1], entry[2], entry[3]))
    elif entry[0] == 'S':
        repo.suppliers.insert(DTO.Supplier(entry[1], entry[2], entry[3]))
Ejemplo n.º 4
0
def main():
    repo = _Repository()
    repo.create_tables()

    # Parsing config file
    with open(sys.argv[1]) as config:
        lines = config.readlines()
        index = 1
        num_of_each = lines[0].split(",")
        vaccines = lines[index:index + int(num_of_each[0])]
        index = index + int(num_of_each[0])
        suppliers = lines[index:index + int(num_of_each[1])]
        index = index + int(num_of_each[1])
        clinics = lines[index:index + int(num_of_each[2])]
        index = index + int(num_of_each[2])
        logistics = lines[index:]
        for line in vaccines:
            line = line.replace("\n", "")
            args = line.split(",")
            repo.vac_dao.insert(
                DTO.Vaccine(int(args[0]), args[1], int(args[2]), int(args[3])))
        for line in suppliers:
            line = line.replace("\n", "")
            args = line.split(",")
            repo.sup_dao.insert(
                DTO.Supplier(int(args[0]), args[1], int(args[2])))
        for line in clinics:
            line = line.replace("\n", "")
            args = line.split(",")
            repo.clin_dao.insert(
                DTO.Clinic(int(args[0]), args[1], int(args[2]), int(args[3])))
        for line in logistics:
            line = line.replace("\n", "")
            args = line.split(",")
            repo.log_dao.insert(
                DTO.Logistic(int(args[0]), args[1], int(args[2]),
                             int(args[3])))

    # Executing orders from orders file
    with open(sys.argv[2]) as orders, open(sys.argv[3], "w") as output:
        lines = orders.readlines()
        for line in lines:
            args = line.split(",")
            if len(args) == 3:
                repo.receive_ship(args[0], int(args[1]), args[2])
            else:
                repo.send_ship(args[0], int(args[1]))
            a, b, c, d = repo.create_record()
            output.write("{},{},{},{}\n".format(a[0], b[0], c[0], d[0]))

    repo.close()
Ejemplo n.º 5
0
def readConfig(filePath):
    with open(filePath, "r") as config:
        amountOfEachPart = config.readline()[0:-1].split(',')
        numOfVaccines = int(amountOfEachPart[0])
        # first read the vaccines
        for x in range(0, numOfVaccines):
            line = config.readline()
            # remove \n at the end of each line if exists
            if "\n" in line:
                vaccineDetails = line[0:-1].split(',')
            else:
                vaccineDetails = line.split(',')
            vaccine = DTO.Vaccine(*vaccineDetails)
            repo.vaccines.insert(vaccine)
            sum.totalInventory += int(vaccineDetails[3])
        # read the suppliers
        numOfSuppliers = int(amountOfEachPart[1])
        for i in range(0, numOfSuppliers):
            line = config.readline()
            # remove \n at the end of each line if exists
            if "\n" in line:
                supplierDetails = line[0:-1].split(',')
            else:
                supplierDetails = line.split(',')
            supplier = DTO.Supplier(*supplierDetails)
            repo.suppliers.insert(supplier)
        # read the clinics
        numOfClinics = int(amountOfEachPart[2])
        for i in range(0, numOfClinics):
            line = config.readline()
            # remove \n at the end of each line if exists
            if "\n" in line:
                clinicDetails = line[0:-1].split(',')
            else:
                clinicDetails = line.split(',')
            clinic = DTO.Clinic(*clinicDetails)
            repo.clinics.insert(clinic)
            sum.totalDemand += int(clinicDetails[2])
        # read the logistics
        numOfLogistics = int(amountOfEachPart[3])
        for i in range(0, numOfLogistics):
            line = config.readline()
            # remove \n at the end of each line if exists
            if "\n" in line:
                logisticDetails = line[0:-1].split(',')
            else:
                logisticDetails = line.split(',')
            logistic = DTO.Logistic(*logisticDetails)
            repo.logistics.insert(logistic)
Ejemplo n.º 6
0
 def find_supplier(self, info, with_what):
     c = self.cursor
     c.execute("SELECT * FROM Suppliers WHERE " + with_what + " = ?",
               [info])
     return DTO.Supplier(*c.fetchone())