def checkForMembership(fName, lName): flag = 0 count = 0 rows = readWriteFile.readFile('NewMember.txt') for row in rows: if row[0] == fName and row[1] == lName: flag = 1 checkRows = readWriteFile.readFile('BookAvailability.txt') for chkrow in checkRows: #member can avail 2 book check if chkrow[3] == fName and chkrow[4] == 'Pending': count += 1 if count == 2: print( "\nSorry, Only 2 books can avail per Member.\nYou have already issued 2 books." ) print("Thank You") exit() if flag == 0: print( "\nYou are not availed for Membership\nPlease be a Member first.\nThank You." ) print("\n\nExiting to Main Page.") readWriteFile.loading('exiting ..........', 2) main.main()
def updateFileDashboard(bName, action): temp = [] rows = readWriteFile.readFile('Materials.txt') for row in rows: if row[0] == bName: if action == 'plus': row[5] = int(row[5]) + 1 else: row[5] = int(row[5]) - 1 temp.append(row) readWriteFile.writeFile('Materials.txt', temp, 'w')
def checkBook(response): rows = readWriteFile.readFile('Materials.txt') Dtime = datetime.datetime.now() flag = 0 for row in rows: if row[0] == response: flag = 1 if row[5] != '0': print(response, "is Available. Quantity: " + row[5] + "/" + row[6]) borrowBook(response) if flag == 0: print("No such book available. Please enter the name CORRECTLY") readWriteFile.loading('Terminating ......', 2) print("Terminated") exit() else: rows = readWriteFile.readFile('BookAvailability.txt') temp = [] for row in rows: #check for min number of days for book availability if row[0] == response and datetime.datetime.strptime( row[2], "%d/%m/%Y") > Dtime: temp.append(row[2]) if len(temp) == 0: print( "\nSorry For the inconvenience cause. The book has not returned from borrower yet." ) print("\nPlease check again tomorrow.") exit() else: dte = min(temp) print( response, "book is currently Unavailable.\nProvisional availability of this book will be on", dte) print("\nThank You, Have a nice Day.") exit()
def displayRows(search, action): rows = readWriteFile.readFile('Materials.txt') i = 0 flag = 0 for row in rows: if i == 0: print("Sr.No|", "|".join(row)) i += 1 else: if re.findall(action, row[search]): #for match case # if row[search] == action: print(i, "|", "|".join(row)) i += 1 flag = 1 if flag == 0: print("No Records Found")
def bookReturn(): print("Enter Name of the book, which you want to return: ") bookName = input() print("Enter your Name: ") borrowerName = input() Dtime = datetime.datetime.now() writeRow = [] flag = 0 # Read the data from BookAvailability.txt rows = readWriteFile.readFile('BookAvailability.txt') for row in rows: if row[3] == borrowerName and row[0] == bookName and row[ 4] == 'Pending': flag = 1 if Dtime <= datetime.datetime.strptime(row[2], "%d/%m/%Y"): row[4] = "Book Returned" print( "Book Returned Successfully\n\nThank You, Please Visit Again" ) dashboard.updateFileDashboard(bookName, "plus") else: # Subtracting due date from Returning date(System Generated Time) dateExceed = Dtime - datetime.datetime.strptime( row[2], "%d/%m/%Y") penalty = dateExceed.days * 10 print( "Your book has Exceeded Due Date.\nPlease pay the penalty fees, Rs", penalty, "/- to the cash counter.") print("\n\nRedirecting to Cash Counter") readWriteFile.loading('payment .........', 2) print("Payment Done") row[4] = "Book Returned" print("\n\nBook Returned Successfully") dashboard.updateFileDashboard(bookName, "plus") print("Thank You, Please Visit Again.") writeRow.append(row) # Write the data to BookAvailability.txt readWriteFile.writeFile('BookAvailability.txt', writeRow, 'w') if flag == 0: print( "\nNo such Book Name/Title found.\nPlease check with the spellings.\nOR\nEnter the value CORRECTLY." ) bookReturn() exit()