def searching_method(donor_data_file, word): lines = file_handler.read_file_content(donor_data_file) result = [] first_line = True counter = 0 for line in lines: if word.lower() in line.lower() and not first_line: splitted_line = line.split(",") if splitted_line not in result: result.append(splitted_line) else: first_line = False if len(result) == 0: print("Searched term was not found.") return True for x in result: counter += 1 if counter <= 4: print_searching_sample(x) else: print(""" 1. Next Page 2. Exit """) next_page_answer = input("Answer: ") if next_page_answer == "1": SCREENCLEAR() counter = 0 print_searching_sample(x) return True
def printing_method(donor_data_file): lines = file_handler.read_file_content(donor_data_file) first_line = True result = [] counter = 0 for line in lines: if not first_line: actual_donor = line.split(",") result.append(actual_donor) elif first_line: first_line = False print("How do you want to sort the list?") print(""" Enter: Name 1. : Gender 2. : Weight 3. : Date of birth 4. : Last donation 5. : Unique identifier 6. : Expiration of id 7. : Blood type 8. : Hemoglobin 9. : Email 10.: Mobil """) answer = input("Answer: ") if answer == "": result.sort(key=lambda res: res[0]) elif answer.isdigit() and int(answer) <= 10: try: result.sort(key=lambda res: int(res[int(answer)])) except: result.sort(key=lambda res: res[int(answer)]) else: return False for line in result: counter += 1 if counter <= 4: print_sample(line) else: print(""" 1. Next Page 2. Exit """) next_page_answer = input("Answer: ") if next_page_answer == "1": SCREENCLEAR() counter = 0 print_sample(line) else: return False return True
def printing_method(donation_data_file): lines = file_handler.read_file_content(donation_data_file) first_line = True result = [] counter = 0 for line in lines: if not first_line: actual_event = line.split(",") result.append(actual_event) elif first_line: first_line = False print("How do you want to sort the list?") print(""" Enter: Date of event 1. : Donation ID 2. : Start time 3. : End time 4. : Zip code 5. : City 6. : Address 7. : Available beds 8. : Planned donor number """) answer = input("Answer: ") if answer == "": result.sort(key=lambda res: res[0]) elif answer.isdigit() and int(answer) <= 8: try: result.sort(key=lambda res: int(res[int(answer)])) except: result.sort(key=lambda res: res[int(answer)]) else: return False for line in result: counter += 1 if counter <= 4: print_sample(line) else: print(""" 1. Next Page 2. Exit """) next_page_answer = input("Answer: ") if next_page_answer == "1": SCREENCLEAR() counter = 0 print_sample(line) else: return False return True
def list_before_delete(donor_data_file): lines = file_handler.read_file_content(donor_data_file) first_line = True result = [] for line in lines: if not first_line and line != "\n": actual_donor = line.split(",") result.append(actual_donor) elif first_line: first_line = False print("Please choose an ID from the list below.") for line in result: print("ID: {0: <8} Name: {1: <30} Birth date: {2: <11}".format(line[6], line[0], line[3])) return True
def list_before_delete(donation_data_file): lines = file_handler.read_file_content(donation_data_file) first_line = True result = [] for line in lines: if not first_line and line != "\n": actual_event = line.split(",") result.append(actual_event) elif first_line: first_line = False print("Please choose an ID from the list below.") for line in result: print("ID: {0: <8} Date of event: {1: <11} City: {2: <20}".format(line[1], line[0], line[5])) return True
def file_changer_donation(Index_to_change,Row_index_to_change,Donation_file_path): lines = file_handler.read_file_content(Donation_file_path) try: if int(Index_to_change) <= 10 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 = DonationEventInput.get_event_data(DonationEventInput.DONATION_HEADER[index],'') 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(Donation_file_path,lines) return True
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