def read_clinics(x, f): for i in range(x): s = f.readline() parser = s[0:-1].split(',') clinic_id = int(parser[0]) location = parser[1] locations.append(location) demand = int(parser[2]) logistic = int(parser[3]) add_clinic(DTO.Clinic(clinic_id, location, demand, logistic))
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()
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)
def find_clinic(self, info, with_what): c = self.cursor c.execute("SELECT * FROM Clinics WHERE " + with_what + " = ?", [info]) return DTO.Clinic(*c.fetchone())