def rem_book(stdscr, bdb: bb.BookDataBase, adb: ab.AuthorDataBase): current_row = 0 book_dict, id_list = bdb.return_dict_by_author() aut_list = adb.return_list() list_copy = list() for i in book_dict: list_copy.append(f"{book_dict[i]} by {aut_list[int(i)]} ") list_copy.append('Exit') while 1: print_list(stdscr, current_row, list_copy, "Books") key = stdscr.getch() if key == curses.KEY_UP and current_row > 0: current_row -= 1 elif key == curses.KEY_DOWN and current_row < len(list_copy) - 1: current_row += 1 elif key == curses.KEY_ENTER or key in [10, 13]: if current_row == len(list_copy) - 1: break else: if bdb.remove_book(id_list[current_row]): bdb.save_books() print_center(stdscr, "Success - press key to return") stdscr.getch() else: print_center(stdscr, "Error - press key to return") stdscr.getch() break
def add_book(stdscr, bdb: bb.BookDataBase): h, w = stdscr.getmaxyx() stdscr.clear() stdscr.addstr(0, w // 2 - len("Title") // 2, "Title") title = read_word(stdscr, h, w) stdscr.clear() stdscr.addstr(0, w // 2 - len("Isbn") // 2, "Isbn") isbn = read_word(stdscr, h, w) stdscr.clear() stdscr.addstr(0, w // 2 - len("Category") // 2, "Category") category = read_word(stdscr, h, w) stdscr.clear() stdscr.addstr(0, w // 2 - len("Author id") // 2, "Author id") aut_id = read_word(stdscr, h, w) book = bk.MyBook(aut_id, title, isbn, category) if bdb.add_book(book): bdb.save_books() print_center(stdscr, "Success - press key to return") stdscr.getch() else: print_center(stdscr, "Error - press key to return") stdscr.getch()