def menu(): connection = database.connect() database.create_tables(connection) while True: user_input = input(MENU_PROMPT) if user_input == "1": name = input("Enter book title: ") author = input("Enter author name: ") rating = int(input("Enter book rating: ")) database.add_book(connection, name, author, rating) break elif user_input == "2": books = database.get_all_books(connection) for book in books: print(f"{book[1]} by {book[2]} - Rating: {book[3]}") elif user_input == "3": name = input("Enter book title: ") books = database.get_books_by_name(connection, name) for book in books: print(f"{book[1]} ({book[2]} - {book[3]}") elif user_input == "4": name = input("Enter the book name: ") highest_rating = database.get_best_rated_books(connection, name) print(f"Highest Rated: {name} - Rating: {highest_rating[3]}") elif user_input == "5": break else: print("Invalid entry")
def add(connection): title = input("What book would you like to add? ") author = input(f"Who is the author of {title}? ") genre = input(f"What genre is {title}? ") rating = input(f"How would you rate {title} out of 10? ") database.add_book(connection, title, author, genre, rating) print(f"You added {title} by {author} to your database.")
def recommendations(): if request.method == "GET": return render_template("add_book.html") else: book_name = request.form["book_name"] author = request.form["author"] genre = request.form["genre"] recommendation = request.form["recommendation"] add_book(book_name, author, genre, recommendation) return render_template("add_book.html")
def menu(): connection = database.connect() database.create_tables(connection) while (user_input := input(MENU_PROMPT)) != "6": #print(user_input) if user_input == "1": nod = input("Cuir nod ann: ") teideal = input("Cuir teideal ann: ") udar = input("Cuir udar ann: ") bp = input("Cuir bliain phróiseála ann: ") database.add_book(connection, nod, teideal, udar, bp) elif user_input == "2": pass books = database.get_all_books(connection) # for book in books: print(book) # elif user_input == "3": pass teideal = input("Cuir isteach teideal leabhair a ba mhaith leat: ") books = database.get_books_by_teideal(connection, teideal) for book in books: print(book) # elif user_input == "4": pass # name = input("Cuir isteach nod an leabhair: ") # books = database.get_books_by_nod(connection,nod) # # for book in books: # print(book) # # for book in books: # print(book) # elif user_input == "5": id = input("Cuir isteach an id: ") book = database.delete_item(connection, id) else: print("Invalid input please try again")
myfile = open(file='../templates/form1.html', mode='r') form = myfile.read() # get user_input from html form, give feedback, update user_inputbase user_input = web.cgi.FieldStorage() mylist = [] if "monography_title" not in user_input or 'copies_quantity' not in user_input: mylist.append("PLEASE ENTER SOME CORRECT VALUES") else: mylist.extend([ 'monography_title', str(type(user_input.getvalue('monography_title'))) ]) for key in ['monography_title', 'copies_quantity']: mylist.append(user_input.getvalue(key)) for key in ['author', 'subject']: for element in user_input.getlist(key): mylist.append(element) # put values in the database monography_title = user_input.getvalue('monography_title') copies_quantity = int(user_input.getvalue('copies_quantity')) author = user_input.getlist('author') subject = user_input.getlist('subject') database.add_book(monography_title, author, subject, copies_quantity) monitor = '<div class="monitor">'+ ' '.join(mylist) + "</div>" web.main_content = form + monitor web.web_page()
def prompt_add_book(): name = input("Enter the neww book name: ") author = input("Enter the new book author: ") database.add_book(name, author)
print('============= Welcome to the Book store ===================') print('=============================================================') while value == 1: user_input = menu_option() if user_input == '1': book_DB = read_bookdata(bookdb_file) for i in range(len(book_DB)): Name = book_DB[i]['name'] Author = book_DB[i]['author'] Read = book_DB[i]['read'] no = i + 1 print(f'{no}. Name - {Name}, Author - {Author}, Read - {Read}') elif user_input == '2': add_book(bookdb_file) elif user_input == '3': book_name = input('Please enter the book name - ') mark_read(book_name, bookdb_file) elif user_input == '4': remove_book(bookdb_file) elif user_input == 'q': value = 0 else: print('Please enter the correct option -')