示例#1
0
    def list_donors(ord_index, path='DATA/donors.csv'):
        with open(path, newline='') as donor_file:
            row_index = 1
            reader = csv.reader(donor_file)
            next(reader)
            lst = []
            if ord_index == 1 or ord_index == 9:
                lst = sorted(reader, key=lambda donor: int(donor[ord_index]))
            else:
                lst = (sorted(reader, key=lambda donor: donor[ord_index].lower()))

            for row in lst:
                print("-" * 35)
                print(str(row_index) + ".")
                row_index += 1
                print("\t" + row[0])
                print("\t" + row[1] + " kg")
                print("\t" + row[3] + " - " + str(calculate_age_in_year(row[3])) + " years old")
                print("\t" + row[10])
                print("-" * 35)
                if row_index > len(lst):
                    input("Press enter to return to main menu.")
                elif row_index % 4 == 0:
                    input("Press enter to list more donors.")
            if len(lst) == 0:
                input("Empty list! Press enter to return to main menu.")
def sorting_row(index,good_index):
    global donor_file, reader, row
    with open('DATA/donors.csv', newline='') as donor_file:
        reader = csv.reader(donor_file)
        for row in reader:
            if row[index].lower() == good[good_index]:
                if "name" in row:
                    continue
                print("-"*35)
                print(str(good_index) + ".")
                print("\t" + row[0])
                print("\t" + row[1] + " kg")
                print("\t" + row[3] + " - " + str(calculate_age_in_year(row[3])) + " years old")
                print("\t" + row[10])
        good_index += 1
        if good_index<len(good):
            sorting_row(index,good_index)
def sorting_row(index, good_index):
    global donor_file, reader, row
    with open('DATA/donors.csv', newline='') as donor_file:
        reader = csv.reader(donor_file)
        for row in reader:
            if row[index].lower() == good[good_index]:
                if "name" in row:
                    continue
                print("-" * 35)
                print(str(good_index) + ".")
                print("\t" + row[0])
                print("\t" + row[1] + " kg")
                print("\t" + row[3] + " - " +
                      str(calculate_age_in_year(row[3])) + " years old")
                print("\t" + row[10])
        good_index += 1
        if good_index < len(good):
            sorting_row(index, good_index)
示例#4
0
 def list_donors(ord_index, cursor):
     cursor.execute("SELECT * FROM Donors ORDER BY " + SortingAsker.donor_header[ord_index] + " ASC")
     ans = cursor.fetchall()
     row_index = 1
     for record in ans:
         row = SqlLister.type_equalizer(record)
         print("-" * 35)
         print(str(row_index) + ".")
         row_index += 1
         print("\t" + row[0])
         print("\t" + row[1] + " kg")
         print("\t" + row[3] + " - " + str(calculate_age_in_year(row[3])) + " years old")
         print("\t" + row[10])
         print("-" * 35)
         if row_index > len(ans):
             input("Press enter to return to main menu.")
         elif row_index % 4 == 0:
             input("Press enter to list more donors.")
         if len(ans) == 0:
             input("Empty list! Press enter to return to main menu.")