def add_new_donor(): print("Adding new donor...\n") time.sleep(1) clear() donor_sample = Donor() donor_sample.name = DonorManager.data_in(donor_sample, Validate.validate_name, "Name: ", NAME_ERR) donor_sample.weight = DonorManager.data_in( donor_sample, Validate.validate_positive_int, "Weight (in KG): ", POSINT_ERR ) donor_sample.gender = DonorManager.data_in(donor_sample, Validate.validate_gender, "Gender (M/F): ", GEND_ERR) donor_sample.dateofbirth = DonorManager.data_in( donor_sample, Validate.validate_date, "Date of Birth: ", DATE_ERR ) donor_sample.lastdonationdate = DonorManager.data_in( donor_sample, Validate.validate_date, "Last Donation: ", DATE_ERR ) if not donor_sample.is_suitable(): print("\n\t - It seems your donor is not suitable for the donation. =( - ") input("\n\n (Press ENTER to go BACK)") clear() return None donor_sample.wassick = DonorManager.data_in( donor_sample, Validate.validate_sickness, "Was he/she sick in the last month? (Y/N) ", SICK_ERR ) donor_sample.uniqueid = DonorManager.data_in(donor_sample, Validate.validate_id, "Unique ID: ", ID_ERR) donor_sample.bloodtype = DonorManager.data_in( donor_sample, Validate.validate_blood_type, "Blood Type: ", BTYPE_ERR ) donor_sample.expofid = DonorManager.data_in( donor_sample, Validate.validate_date, "Expiration of ID: ", DATE_ERR ) donor_sample.emailaddress = DonorManager.data_in( donor_sample, Validate.validate_email, "Email address: ", EMAIL_ERR ) donor_sample.mobilnumber = DonorManager.data_in( donor_sample, Validate.validate_mobilnumber, "Mobile Number: ", MOBILE_ERR ) with open("Data/donors.csv", "a") as f: f.write(donor_sample.name + ",") f.write(donor_sample.weight + ",") f.write(donor_sample.gender + ",") f.write(donor_sample.dateofbirth + ",") f.write(donor_sample.lastdonationdate + ",") f.write(donor_sample.wassick + ",") f.write(donor_sample.uniqueid + ",") f.write(donor_sample.expofid + ",") f.write(donor_sample.bloodtype + ",") f.write(donor_sample.generate_hemoglobin_level() + ",") f.write(donor_sample.emailaddress + ",") f.write(donor_sample.mobilnumber + "\n") print("\n - Your donor is added to the csv -\n\n Going back to main menu...") time.sleep(2.5) clear()
def list_donors(cursor): cursor.execute("SELECT * FROM Donor;") donor_list = cursor.fetchall() if len(donor_list) < 1: print("\n No entry found\n") input("\n Press (ENTER) to go back") clear() return None else: donor_object_list = [] for l in donor_list: next_donor = Donor() next_donor.uniqueid = l[0] next_donor.name = l[1] next_donor.weight = str(l[2]) next_donor.gender = l[3] next_donor.dateofbirth = datetime.date.strftime( l[4], "%Y.%m.%d") next_donor.lastdonationdate = datetime.date.strftime( l[5], "%Y.%m.%d") next_donor.wassick = l[6] next_donor.bloodtype = l[7] next_donor.expofid = datetime.date.strftime(l[8], "%Y.%m.%d") next_donor.hemoglobin = l[9] next_donor.emailaddress = l[-2] next_donor.mobilnumber = str(l[-1]) next_donor.age = next_donor.donor_age() donor_object_list.append(next_donor) sort_by_input = input( "Please choose the criteria by which you would like to sort the list: " "\n\n(ENTER) or (1) by name\n(2) by weight\n(3) by gender\n(4) by birth date" "\n(5) by date of last donation\n(6) by health status in last month" "\n(7) by ID or Passport number\n(8) by expiration date of ID" "\n(9) by blood type\n(10) by hemoglobin\n(11) by e-mail address" "\n(12) by mobile number\n(13) by age\n(0) Cancel\n\n> ") clear() if sort_by_input == "": sort_by_input = "1" if sort_by_input.isdigit() and int(sort_by_input) in range(1, 14): DonorManagerDB.print_sorted_donor_list(donor_object_list, sort_by_input) return None elif sort_by_input == "0": clear() return None else: print( "\n\t\t! ! ! Please choose from the given numbers. ! ! !\t\t\n " ) time.sleep(1.5) clear()
def list_donors(): with open("Data/donors.csv", "r") as f: donor_list = list(csv.reader(f)) del (donor_list[0]) if len(donor_list) < 1: print("\n No entry found\n") input("\n Press (ENTER) to go back") clear() return None else: donor_object_list = [] for l in donor_list: next_donor = Donor() next_donor.name = l[0] next_donor.weight = l[1] next_donor.gender = l[2] next_donor.dateofbirth = l[3] next_donor.lastdonationdate = l[4] next_donor.wassick = l[5] next_donor.uniqueid = l[6] next_donor.expofid = l[7] next_donor.bloodtype = l[8] next_donor.hemoglobin = l[9] next_donor.emailaddress = l[-2] next_donor.mobilnumber = l[-1] next_donor.age = next_donor.donor_age() donor_object_list.append(next_donor) sort_by_input = input( "Please choose the criteria by which you would like to sort the list: " "\n\n(ENTER) or (1) by name\n(2) by weight\n(3) by gender\n(4) by birth date" "\n(5) by date of last donation\n(6) by health status in last month" "\n(7) by ID or Passport number\n(8) by expiration date of ID" "\n(9) by blood type\n(10) by hemoglobin\n(11) by e-mail address" "\n(12) by mobile number\n(13) by age\n(0) Cancel\n\n> " ) clear() if sort_by_input == "": sort_by_input = "1" if sort_by_input.isdigit() and int(sort_by_input) in range(1, 14): DonorManager.print_sorted_donor_list(donor_object_list, sort_by_input) return None elif sort_by_input == "0": clear() return None else: print("\n\t\t! ! ! Please choose from the given numbers. ! ! !\t\t\n ") time.sleep(1.5) clear()
def change_donor_data(data_input, cursor): input_donor_data_pairs = {0: "Name", 1: "Weight", 2: "Gender", 3: "DateOfBirth", 4: "LastDonationDate", 5: "Wassick", 6: "UniqueId", 7: "ExpofId", 8: "BloodType", 9: "HemoglobinLevel", 10: "Emailaddress", 11: "Mobilnumber"} which_donor_data_validation = {0: Validate.validate_name, 1: Validate.validate_positive_int, 2: Validate.validate_gender, 3: Validate.validate_date, 4: Validate.validate_date, 5: Validate.validate_sickness, 6: Validate.validate_id, 7: Validate.validate_date, 8: Validate.validate_blood_type, 9: Validate.validate_positive_int, 10: Validate.validate_email, 11: Validate.validate_mobilnumber} actv_selection = 0 while True: cursor.execute("SELECT * FROM Donor;") data = cursor.fetchall() sor = [] donor_list = [] for i in data: sor.append(i[1]) sor.append(str(i[2])) sor.append(i[3]) sor.append(datetime.date.strftime(i[4], "%Y.%m.%d")) sor.append(datetime.date.strftime(i[5], "%Y.%m.%d")) sor.append(i[6]) sor.append(i[0]) sor.append(datetime.date.strftime(i[8], "%Y.%m.%d")) sor.append(i[7]) sor.append(str(i[11])) sor.append(i[9]) sor.append(i[10]) donor_list.append(sor) cursor.execute("SELECT UniqueId FROM Donor;") data = cursor.fetchall() ids = [i[0] for i in data] if data_input in ids: for l in donor_list: next_donor = Donor() next_donor.name = l[0] next_donor.weight = l[1] next_donor.gender = l[2] next_donor.dateofbirth = l[3] next_donor.lastdonationdate = l[4] next_donor.wassick = l[5] next_donor.uniqueid = l[6] next_donor.expofid = l[7] next_donor.bloodtype = l[8] next_donor.hemoglobin = l[9] next_donor.emailaddress = l[-2] next_donor.mobilnumber = l[-1] else: print("Data entry doesn't exist with that ID.") time.sleep(1) return None MenuManager.change_donor_submenu(actv_selection, next_donor) key = ord(getch()) if key == ESC: user_input = 12 clear() elif key == ENTER: user_input = actv_selection clear() elif key == SPECIALKEYSELECTOR: key = ord(getch()) if key == DOWNARROW: if actv_selection < 12: actv_selection += 1 continue elif key == UPARROW: if actv_selection > 0: actv_selection -= 1 continue else: print("\n! Wrong key !") time.sleep(1) continue else: print("\n! Wrong key !") time.sleep(1) continue if user_input in range(12): new = "" while new == "": clear() print(next_donor) print("------------------------------\n") new = input("\n(0) Cancel\nChanging {} to: ".format(input_donor_data_pairs[user_input])) if new == "0": return None if which_donor_data_validation[user_input](new): cursor.execute("UPDATE donor \ SET \ `{}` = '{}' \ WHERE `UniqueId` = '{}';".format(input_donor_data_pairs[user_input], new, data_input)) print('\n...Done!') time.sleep(1) break else: print("Wrong input") new = "" time.sleep(1) elif user_input == 12: clear() actv_selection = 0 return None
def add_new_donor(): print("Adding new donor...\n") time.sleep(1) clear() donor_sample = Donor() donor_sample.name = DonorManager.data_in(donor_sample, Validate.validate_name, "Name: ", NAME_ERR) donor_sample.weight = DonorManager.data_in( donor_sample, Validate.validate_positive_int, "Weight (in KG): ", POSINT_ERR) donor_sample.gender = DonorManager.data_in(donor_sample, Validate.validate_gender, "Gender (M/F): ", GEND_ERR) donor_sample.dateofbirth = DonorManager.data_in( donor_sample, Validate.validate_date, "Date of Birth: ", DATE_ERR) donor_sample.lastdonationdate = DonorManager.data_in( donor_sample, Validate.validate_date, "Last Donation: ", DATE_ERR) if not donor_sample.is_suitable(): print( "\n\t - It seems your donor is not suitable for the donation. =( - " ) input("\n\n (Press ENTER to go BACK)") clear() return None donor_sample.wassick = DonorManager.data_in( donor_sample, Validate.validate_sickness, "Was he/she sick in the last month? (Y/N) ", SICK_ERR) donor_sample.uniqueid = DonorManager.data_in(donor_sample, Validate.validate_id, "Unique ID: ", ID_ERR) donor_sample.bloodtype = DonorManager.data_in( donor_sample, Validate.validate_blood_type, "Blood Type: ", BTYPE_ERR) donor_sample.expofid = DonorManager.data_in(donor_sample, Validate.validate_date, "Expiration of ID: ", DATE_ERR) donor_sample.emailaddress = DonorManager.data_in( donor_sample, Validate.validate_email, "Email address: ", EMAIL_ERR) donor_sample.mobilnumber = DonorManager.data_in( donor_sample, Validate.validate_mobilnumber, "Mobile Number: ", MOBILE_ERR) with open("Data/donors.csv", "a") as f: f.write(donor_sample.name + ",") f.write(donor_sample.weight + ",") f.write(donor_sample.gender + ",") f.write(donor_sample.dateofbirth + ",") f.write(donor_sample.lastdonationdate + ",") f.write(donor_sample.wassick + ",") f.write(donor_sample.uniqueid + ",") f.write(donor_sample.expofid + ",") f.write(donor_sample.bloodtype + ",") f.write(donor_sample.generate_hemoglobin_level() + ",") f.write(donor_sample.emailaddress + ",") f.write(donor_sample.mobilnumber + "\n") print( "\n - Your donor is added to the csv -\n\n Going back to main menu..." ) time.sleep(2.5) clear()
def change_donor_data(data_input): with open('Data/donors.csv', 'r') as f: donor_list = list(csv.reader(f)) del (donor_list[0]) if data_input in [i[6] for i in donor_list]: for i, l in enumerate(donor_list): if data_input == l[6]: next_donor = Donor() next_donor.name = l[0] next_donor.weight = l[1] next_donor.gender = l[2] next_donor.dateofbirth = l[3] next_donor.lastdonationdate = l[4] next_donor.wassick = l[5] next_donor.uniqueid = l[6] next_donor.expofid = l[7] next_donor.bloodtype = l[8] next_donor.hemoglobin = l[9] next_donor.emailaddress = l[-2] next_donor.mobilnumber = l[-1] line_number = i else: print("Data entry doesn't exist with that ID.") time.sleep(1) return None input_donor_data_pairs = { 0: "Name", 1: "Weight", 2: "Gender", 3: "Date of birth", 4: "Last donation date", 5: "Health status in last month", 6: "ID number", 7: "Expiration of ID", 8: "Blood Type", 9: "Hemoglobin", 10: "e-mail address", 11: "Mobil number" } which_donor_data_validation = { 0: Validate.validate_name, 1: Validate.validate_positive_int, 2: Validate.validate_gender, 3: Validate.validate_date, 4: Validate.validate_date, 5: Validate.validate_sickness, 6: Validate.validate_id, 7: Validate.validate_date, 8: Validate.validate_blood_type, 9: Validate.validate_positive_int, 10: Validate.validate_email, 11: Validate.validate_mobilnumber } actv_selection = 0 while True: MenuManager.change_donor_submenu(actv_selection, next_donor) key = ord(getch()) if key == ESC: user_input = 12 clear() elif key == ENTER: user_input = actv_selection clear() elif key == SPECIALKEYSELECTOR: key = ord(getch()) if key == DOWNARROW: if actv_selection < 12: actv_selection += 1 continue elif key == UPARROW: if actv_selection > 0: actv_selection -= 1 continue else: print("\n! Wrong key !") time.sleep(1) continue else: print("\n! Wrong key !") time.sleep(1) continue if user_input in range(12): new = "" while new == "": clear() print(next_donor) print("------------------------------\n") new = input("\n(0) Cancel\nChanging {} to: ".format( input_donor_data_pairs[user_input])) if new == "0": return None if new.upper() in [donor[6] for donor in donor_list]: print("This ID number already exists! Try again.") time.sleep(2) break if which_donor_data_validation[user_input](new): with open("Data/donors.csv", "w") as f: donor_list[line_number][user_input] = new.upper() f.write(DONORS_ELSOSOR) for line in donor_list: for i in range(len(line)): f.write(line[i]) if i < len(line) - 1: f.write(',') f.write('\n') print('\n...Done!') time.sleep(1) break else: print("Wrong input") new = "" time.sleep(1) elif user_input == 12: clear() actv_selection = 0 return None
def change_donor_data(data_input): with open("Data/donors.csv", "r") as f: donor_list = list(csv.reader(f)) del (donor_list[0]) if data_input in [i[6] for i in donor_list]: for i, l in enumerate(donor_list): if data_input == l[6]: next_donor = Donor() next_donor.name = l[0] next_donor.weight = l[1] next_donor.gender = l[2] next_donor.dateofbirth = l[3] next_donor.lastdonationdate = l[4] next_donor.wassick = l[5] next_donor.uniqueid = l[6] next_donor.expofid = l[7] next_donor.bloodtype = l[8] next_donor.hemoglobin = l[9] next_donor.emailaddress = l[-2] next_donor.mobilnumber = l[-1] line_number = i else: print("Data entry doesn't exist with that ID.") time.sleep(1) return None input_donor_data_pairs = { 0: "Name", 1: "Weight", 2: "Gender", 3: "Date of birth", 4: "Last donation date", 5: "Health status in last month", 6: "ID number", 7: "Expiration of ID", 8: "Blood Type", 9: "Hemoglobin", 10: "e-mail address", 11: "Mobil number", } which_donor_data_validation = { 0: Validate.validate_name, 1: Validate.validate_positive_int, 2: Validate.validate_gender, 3: Validate.validate_date, 4: Validate.validate_date, 5: Validate.validate_sickness, 6: Validate.validate_id, 7: Validate.validate_date, 8: Validate.validate_blood_type, 9: Validate.validate_positive_int, 10: Validate.validate_email, 11: Validate.validate_mobilnumber, } actv_selection = 0 while True: MenuManager.change_donor_submenu(actv_selection, next_donor) key = ord(getch()) if key == ESC: user_input = 12 clear() elif key == ENTER: user_input = actv_selection clear() elif key == SPECIALKEYSELECTOR: key = ord(getch()) if key == DOWNARROW: if actv_selection < 12: actv_selection += 1 continue elif key == UPARROW: if actv_selection > 0: actv_selection -= 1 continue else: print("\n! Wrong key !") time.sleep(1) continue else: print("\n! Wrong key !") time.sleep(1) continue if user_input in range(12): new = "" while new == "": clear() print(next_donor) print("------------------------------\n") new = input("\n(0) Cancel\nChanging {} to: ".format(input_donor_data_pairs[user_input])) if new == "0": return None if new.upper() in [donor[6] for donor in donor_list]: print("This ID number already exists! Try again.") time.sleep(2) break if which_donor_data_validation[user_input](new): with open("Data/donors.csv", "w") as f: donor_list[line_number][user_input] = new.upper() f.write(DONORS_ELSOSOR) for line in donor_list: for i in range(len(line)): f.write(line[i]) if i < len(line) - 1: f.write(",") f.write("\n") print("\n...Done!") time.sleep(1) break else: print("Wrong input") new = "" time.sleep(1) elif user_input == 12: clear() actv_selection = 0 return None
def change_donor_data(data_input, cursor): input_donor_data_pairs = { 0: "Name", 1: "Weight", 2: "Gender", 3: "DateOfBirth", 4: "LastDonationDate", 5: "Wassick", 6: "UniqueId", 7: "ExpofId", 8: "BloodType", 9: "HemoglobinLevel", 10: "Emailaddress", 11: "Mobilnumber" } which_donor_data_validation = { 0: Validate.validate_name, 1: Validate.validate_positive_int, 2: Validate.validate_gender, 3: Validate.validate_date, 4: Validate.validate_date, 5: Validate.validate_sickness, 6: Validate.validate_id, 7: Validate.validate_date, 8: Validate.validate_blood_type, 9: Validate.validate_positive_int, 10: Validate.validate_email, 11: Validate.validate_mobilnumber } actv_selection = 0 while True: cursor.execute("SELECT * FROM Donor;") data = cursor.fetchall() sor = [] donor_list = [] for i in data: sor.append(i[1]) sor.append(str(i[2])) sor.append(i[3]) sor.append(datetime.date.strftime(i[4], "%Y.%m.%d")) sor.append(datetime.date.strftime(i[5], "%Y.%m.%d")) sor.append(i[6]) sor.append(i[0]) sor.append(datetime.date.strftime(i[8], "%Y.%m.%d")) sor.append(i[7]) sor.append(str(i[11])) sor.append(i[9]) sor.append(i[10]) donor_list.append(sor) cursor.execute("SELECT UniqueId FROM Donor;") data = cursor.fetchall() ids = [i[0] for i in data] if data_input in ids: for l in donor_list: next_donor = Donor() next_donor.name = l[0] next_donor.weight = l[1] next_donor.gender = l[2] next_donor.dateofbirth = l[3] next_donor.lastdonationdate = l[4] next_donor.wassick = l[5] next_donor.uniqueid = l[6] next_donor.expofid = l[7] next_donor.bloodtype = l[8] next_donor.hemoglobin = l[9] next_donor.emailaddress = l[-2] next_donor.mobilnumber = l[-1] else: print("Data entry doesn't exist with that ID.") time.sleep(1) return None MenuManager.change_donor_submenu(actv_selection, next_donor) key = ord(getch()) if key == ESC: user_input = 12 clear() elif key == ENTER: user_input = actv_selection clear() elif key == SPECIALKEYSELECTOR: key = ord(getch()) if key == DOWNARROW: if actv_selection < 12: actv_selection += 1 continue elif key == UPARROW: if actv_selection > 0: actv_selection -= 1 continue else: print("\n! Wrong key !") time.sleep(1) continue else: print("\n! Wrong key !") time.sleep(1) continue if user_input in range(12): new = "" while new == "": clear() print(next_donor) print("------------------------------\n") new = input("\n(0) Cancel\nChanging {} to: ".format( input_donor_data_pairs[user_input])) if new == "0": return None if which_donor_data_validation[user_input](new): cursor.execute("UPDATE donor \ SET \ `{}` = '{}' \ WHERE `UniqueId` = '{}';".format( input_donor_data_pairs[user_input], new, data_input)) print('\n...Done!') time.sleep(1) break else: print("Wrong input") new = "" time.sleep(1) elif user_input == 12: clear() actv_selection = 0 return None