Exemplo n.º 1
0
 def find(self, logistic):  # retrieve Logistic DTO
     c = self._dbcon.cursor()
     c.execute(
         """
         SELECT id, name FROM logistics WHERE id = ?
     """, [logistic])
     return DTO.Logistic(*c.fetchone())
Exemplo n.º 2
0
def read_logistics(x, f):
    for i in range(x):
        s = f.readline()
        parser = s[0:-1].split(',')
        if i == x - 1:
            parser = s.split(',')
        logistic_id = int(parser[0])
        name = parser[1]
        count_sent = int(parser[2])
        count_received = int(parser[3])
        add_logistic(DTO.Logistic(logistic_id, name, count_sent, count_received))
Exemplo n.º 3
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()
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def read_insert(self, config_file):
        with open(config_file) as f:
            f = f.readlines()  # f stands for file -- make my file a list
        config_first_line = f[0]
        config_first_line = config_first_line[:-1]
        split_config_first_line = config_first_line.split(",")

        list_entries_vaccines = []
        list_entries_suppliers = []
        list_entries_clinics = []
        list_entries_logistics = []
        lines_to_read_vac = int(split_config_first_line[0])
        lines_to_read_sup = int(split_config_first_line[1])
        lines_to_read_clin = int(split_config_first_line[2])
        lines_to_read_log = int(split_config_first_line[3])
        range1 = range(1, 1 + lines_to_read_vac)
        range2 = range(1 + lines_to_read_vac,
                       lines_to_read_sup + 1 + lines_to_read_vac)
        range3 = range(
            lines_to_read_sup + 1 + lines_to_read_vac,
            lines_to_read_sup + 1 + lines_to_read_vac + lines_to_read_clin)
        range4 = range(
            lines_to_read_sup + 1 + lines_to_read_vac + lines_to_read_clin,
            lines_to_read_sup + 1 + lines_to_read_vac + lines_to_read_clin +
            lines_to_read_log)

        for i in range1:
            list_entries_vaccines.append(f[i])
        for i in range2:
            list_entries_suppliers.append(f[i])
        for i in range3:
            list_entries_clinics.append(f[i])
        for i in range4:
            list_entries_logistics.append(f[i])

        for i in list_entries_vaccines:
            i = i[:-1]
            i = i.split(',')
            vaccine = DTO.Vaccines(*i)
            insert_vac = DAO.Vaccines(self._dbcon)
            insert_vac.insert(vaccine)

        for i in list_entries_suppliers:
            i = i[:-1]
            i = i.split(',')
            supplier = DTO.Suppliers(*i)
            insert_sup = DAO.Suppliers(self._dbcon)
            insert_sup.insert(supplier)

        for i in list_entries_clinics:
            i = i[:-1]
            i = i.split(',')
            clinic = DTO.Clinics(*i)
            insert_cli = DAO.Clinics(self._dbcon)
            insert_cli.insert(clinic)

        for i in list_entries_logistics:
            if i[-1] == '\n':
                i = i[:-1]
            i = i.split(',')
            logistic = DTO.Logistic(*i)
            insert_log = DAO.Logistics(self._dbcon)
            insert_log.insert(logistic)
Exemplo n.º 6
0
 def find_logistic(self, logistic_id):
     c = self.cursor
     c.execute("SELECT * FROM Logistics WHERE id = ?", [logistic_id])
     return DTO.Logistic(*c.fetchone())