def file_changer_donor(Index_to_change,Row_index_to_change,Donor_file_path): lines = file_handler.read_file_content(Donor_file_path) try: if int(Index_to_change) <= 12 and int(Index_to_change) >= 1: index = int(Index_to_change) - 1 line = int(Row_index_to_change) else: return False except: return False print("Old line: {}".format(lines[line])) change = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[index],'') if index == 6: if not file_handler.check_if_id_not_in_file(Donor_file_path,change): input("Id already in file.") return False split_line = lines[line].split(",") split_line[index] = change new_line = ",".join(split_line) lines[Row_index_to_change] = new_line file_handler.rewrite_file_with_data(Donor_file_path,lines) return True
def get_data_from_input(self): try: self.name = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[0], "firstname lastname") self.gender = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[1], "m/M - f/F") self.weight = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[2], "99") if not self.check_weight(): sleep(3) raise ValueError self.birth_date = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[3], "YYYY.MM.DD") if not self.check_age(): sleep(3) raise ValueError self.last_donation = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[4], "YYYY.NN.DD") if not self.check_last_donation(): print("Attention! The last donation date is within %s days." % MIN_NUMBER_OF_DAYS_FROM_LAST_DONATION) self.was_sick_last_month = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[5], "y/n") self.identifier = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[6], "ANCDEF12/123456AB") self.id_expire = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[7], "YYYY.MM.DD") if not self.check_id_expiration(): sleep(3) raise ValueError self.blood_type = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[8], "A+, A-, B+, B-, AB+, AB-, 0+, 0-") self.e_mail = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[10], "[email protected]/.hu") self.mobile_number = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[11], "+36301234567/06209876543") except ValueError: return