Trending ▼   ResFinder  

Maharashtra Board Class 9 Exam 2025 : Chemistry

57 pages, 67 questions, 0 questions with responses, 0 total responses,    0    0
Utsa Nag
Assembly of Angels Secondary School, Barrackpore
9 Computer Applications and Science And English
+Fave Message
 Home > utsa86 >

Formatting page ...

PM SHRI KENDRIYA VIDYALAYA BERHAMPUR COMPUTER SCIENCE PROJECT 2023-24 PROJECT TOPIC: LIBRARY MANAGEMENT SYSTEM Submitted by: Name: BIBHASINDHU PRADHAN Class: XII-A CBSE Roll Number: Under the Guidance of: SAROJ KANTA MISRA, PGT (CS) CERTIFICATE This is to certify that BIBHASINDHU PRADHAN of class: XII - A of KENDRIYA VIDYALAYA BERHAMPUR has done his project on LIBRARY MANAGEMENT SYSTEM (DIGITAL LIBRARY) under my supervision. He has taken interest and has shown at most sincerity in completion of this project. I certify this project up to my expectation & as per guidelines issued by CBSE, NEW DELHI. Internal Examiner External Examiner Principal 1|Page ACKNOWLEDGMENT It is with pleasure that I acknowledge my sincere gratitude to our teacher, MR. SAROJ KANTA MISRA, PGT (CS) who taught and undertook the responsibility of teaching the subject computer science. I have been greatly benefited from his classes. I am especially indebted to our Principal MR. SHIVAPRIYA DASH who has always been a source of encouragement and support and without whose inspiration this project would not have been a successful I would like to place on record heartfelt thanks to him. Finally, I would like to express my sincere appreciation for all the other students for my batch their friendship & the fine time that we all shared together. 2|Page HARDWARES AND SOFTWARES REQUIRED HARDWARES 1. Desktop Computer / Laptop 2. Mobile Phone SOFTWARES 1. Python (Latest Version) 2. MySQL 3. MySQL-Connector-Python,Requests,Wikipedia-API, Datetime, Pyfiglet Modules 3|Page TABLE OF CONTENTS S.No. Topic Page No. 1 Certificate 1 2 Acknowledgement 2 3 Hardwares and Softwares Required 3 4 Introduction 5 5 Python Source Code 10 6 MySQL Database 45 7 Outputs 48 8 References 56 4|Page INTRODUCTION The project LIBRARY MANAGEMENT SYSTEM (DIGITAL LIBRARY) includes enrolment of users, adding of books into the library system. The software has the facility to search for news, Wikipedia articles. It includes an authentication facility for admin and user to login into the admin panel and user panel resp. of the system. User can see the books available, details of books issued by the user in the digital library. The Library Management System can be login using a user ID and password. It is accessible either by an admin or user. Only the admin can add, delete and update the data of users and books into the database. The data can be retrieved easily. The interface is very user-friendly. The data are well protected for personal use and makes the data processing very fast. The purpose of the project entitled as DIGITAL LIBRARY is to computerize the Front Library Management to develop software which is user friendly, simple, fast, and costeffective. It also has a notes facility where the user can add notes at any point of the program into the database. 5|Page LIBRARY A library is a collection of books, and possibly other materials and media, that is accessible for use by its members and members of allied institutions. Libraries provide physical or digital materials, and may be a physical location, a virtual space, or both. A library's collection normally includes printed materials which may be borrowed, and usually also includes a reference section of publications which may only be utilized inside the premises. Libraries can vary widely in size and may be organised and maintained by a public body such as a government, an institution (such as a school or museum), a corporation, or a private individual. In addition to providing materials, libraries also provide the services of librarians who are trained experts in finding, selecting, circulating and organising information while interpreting information needs and navigating and analysing large amounts of information with a variety of resources. 6|Page LIBRARY MANAGEMENT SYSTEM (DIGITAL LIBRARY) Library management system (LMS), is an enterprise resource planning system for a library, used to track enrolled users, available books, books issued and to whom, books returned and it s fines, etc. The purpose of a library management system is to operate a library with efficiency and at reduced costs. The system being entirely automated streamlines all the tasks involved in operations of the library. The library management system software helps in reducing operational costs. Managing a library manually is labour intensive and an immense amount of paperwork is involved. The system saves time for both the user and the librarian. With just a click the user can search for the books available in the library. The librarian can answer queries with ease regarding the availability of books. Adding, removing or editing the database is a simple process. Adding new users or cancelling existing userships can be done with ease. The automated system saves a considerable amount of time as opposed to the manual system. 7|Page FUNCTIONS LIST Admin Login into User Panel Modify User Add User Delete User Update User Display Users Search Users Modify Book Add Book Delete Book Update Book Issue Book Return Book Change Admin Home Back Exit User About Library 8|Page News Wikipedia Articles Display Books Search Books Issued Books Details Notes Modify Notes o Add Notes o Delete Notes o Update Notes Display Notes Search Notes Home Back Exit 9|Page Python Source Code 10 | P a g e 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 # Importing necessary libraries import mysql.connector import pyfiglet import requests import wikipediaapi from datetime import datetime # Connect to the MySQL database db = mysql.connector.connect( host="localhost", user="root", password="admin", database="library", ) c = db.cursor() # Function to display the return policy information def returnPolicy(): print("Return Policy : ") print("The issued book should be returned within 14 days(2 weeks).") print( "If the user kept the issued book for more than 14 days, then the user have to pay 5 as fine for each extra day the user kept the issued book." ) print("--------------------------") # Function to calculate the length of a given integer after converting it to a string def length(i): s = str(i) length = len(s) + 2 return length # Function to display a message for an invalid option def validOption(): print("Please enter a valid option!") print("--------------------------") # Function to handle program exit def exiting(): print("\033[3;34m--------------------------\033[0;0m") print("\033[3;33mExiting the program.") print("Thank You!\033[0;0m") print("\033[3;34m--------------------------\033[0;0m") exit() # Function to display the user menu and handle user choices def userMenu(): # Displaying options for the user print("1. Add Note") print("2. Home") print("3. Back") print("4. Exit") # Taking user choice as input userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices 11 | P a g e 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 if userChoice == 1: addNote() elif userChoice == 2: home() elif userChoice == 3: user() elif userChoice == 4: exiting() else: validOption() # Function to display information about the library def aboutLibrary(): # Retrieve the name of the librarian who is also an admin c.execute("SELECT userName FROM users WHERE adminStatus='admin'") userName = c.fetchall() # Retrieve the total number of books and users in the library c.execute("SELECT * FROM books") totalBooks = c.fetchall() c.execute("SELECT * FROM users") totalUsers = c.fetchall() db.commit() print("--------------------------") print("About Library") print("--------------------------") # Display library information print("Year of Library's Establishment : ", 2023) print("Name of the Librarian : ", userName[0][0]) print("Total Number of Books Available in the Library : ", len(totalBooks)) print("Total Number of Users Enrolled in the Library : ", len(totalUsers)) print("--------------------------") userMenu() # Function to display the list of books in the library def displayBooks(): print("--------------------------") print("Display Books") print("--------------------------") # Retrieve all books from the database c.execute("SELECT * FROM books ORDER BY bookId") result = c.fetchall() db.commit() # Display books if available, otherwise notify the user if result: print("Books available in the Digital Library are :") print("--------------------------") i = 0 for row in result: i += 1 r = length(i) print(f"{i}. Book ID : {row[0]}") print(" " * r + f"Book Name : {row[1]}") print(" " * r + f"Publication Year : {row[2]}") print(" " * r + f"Author Name : {row[7]}") print(" " * r + f"Issue Status : {row[8]}") print("--------------------------") userMenu() else: 12 | P a g e 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 # Notify the user if no books are found print("No books found.") print("--------------------------") userMenu() # Search books menu options def searchBooksMenu(): print("1. Add Note") print("2. Home") print("3. Back") print("4. Exit") userChoice = int(input("Enter your Choice to Continue : ")) # User choices handling if userChoice == 1: addNote() elif userChoice == 2: home() elif userChoice == 3: searchBooks() elif userChoice == 4: exiting() else: validOption() # Function to search books by Book ID def searchBooksbyId(): print("--------------------------") print("Search Books by Book ID") print("--------------------------") # Get user input for Book ID bookId = int(input("Enter the Book ID to search the Book : ")) print("--------------------------") # Execute SQL query to retrieve book information by Book ID c.execute("SELECT * FROM books WHERE bookId=%s", (bookId,)) result = c.fetchall() db.commit() # Display search results if books are found, otherwise notify the user if result: print(f'Book available in the Digital Library with the Book ID "{bookId}" is :') print("--------------------------") i = 0 for row in result: i += 1 r = length(i) print(f"{i}. Book ID : {row[0]}") print(" " * r + f"Book Name : {row[1]}") print(" " * r + f"Publication Year : {row[2]}") print(" " * r + f"Author Name : {row[7]}") print(" " * r + f"Issue Status : {row[8]}") print("--------------------------") searchBooksMenu() else: print(f'No book found with the book id "{bookId}".') print("--------------------------") searchBooksMenu() # Function to search books by keyword def searchBooksbyKeyword(): print("--------------------------") 13 | P a g e 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 print("Search Books by Keyword") print("--------------------------") # Get user input for keyword keyword = input("Enter a Keyword to search Books : ") print("--------------------------") # Execute SQL query to retrieve books by keyword c.execute( "SELECT * FROM books WHERE bookName LIKE '%{}%' ORDER BY bookId".format(keyword) ) result = c.fetchall() db.commit() # Display search results if books are found, otherwise notify the user if result: print( f'Books available in the Digital Library with the Keyword "{keyword}" are :' ) print("--------------------------") i = 0 for row in result: i += 1 r = length(i) print(f"{i}. Book ID : {row[0]}") print(" " * r + f"Book Name : {row[1]}") print(" " * r + f"Publication Year : {row[2]}") print(" " * r + f"Author Name : {row[7]}") print(" " * r + f"Issue Status : {row[8]}") print("--------------------------") searchBooksMenu() else: print(f'No books found with the keyword "{keyword}".') print("--------------------------") searchBooksMenu() # Function to display search options for books def searchBooks(): print("--------------------------") print("Search Books") print("--------------------------") print("1. Search by Book ID") print("2. Search by Keyword") print("3. Home") print("4. Back") print("5. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # User choices handling if userChoice == 1: searchBooksbyId() elif userChoice == 2: searchBooksbyKeyword() elif userChoice == 3: home() elif userChoice == 4: user() elif userChoice == 5: exiting() else: validOption() 14 | P a g e 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 # Function to display the add book menu and handle user choices def addBookMenu(): # Add book menu options print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # User choices handling if userChoice == 1: home() elif userChoice == 2: modifyBook() elif userChoice == 3: exiting() else: validOption() # Function to add a new book to the library def addBook(): print("--------------------------") print("Add Book") print("--------------------------") # Get user input for book details bookId = int(input("Enter the Book ID : ")) bookName = input("Enter the Book Name : ") publicationYear = int(input("Enter the Book Publication Year : ")) author = input("Enter the Book Author Name : ") print("--------------------------") c.execute("SELECT bookId FROM books") result = c.fetchall() db.commit() if (bookId,) in result: print( f'The book of book id "{bookId}" is already available in the digital library.' ) print("--------------------------") addBookMenu() else: # Execute SQL query to insert the new book into the database c.execute( "INSERT INTO books (bookId, bookName, publicationYear, author) VALUES (%s, %s, %s, %s)", (bookId, bookName, publicationYear, author), ) db.commit() # Notify the user that the book has been added successfully print("Book added Successfully!") print("--------------------------") addBookMenu() # Function to display the delete book menu and handle user choices def deleteBookMenu(): # Delete book menu options print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") 15 | P a g e 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 # User choices handling if userChoice == 1: home() elif userChoice == 2: admin() elif userChoice == 3: exiting() else: validOption() # Function to delete a book from the library def deleteBook(): print("--------------------------") print("Delete Book") print("--------------------------") # Get user input for the book ID to be deleted bookId = int(input("Enter the Book ID : ")) choice = input("Are you sure to delete the Book? (Yes/No) : ") print("--------------------------") c.execute("SELECT bookId FROM books") result = c.fetchall() db.commit() if choice.lower() in ["yes", "y"]: if (bookId,) in result: # Execute SQL query to delete the book from the database c.execute("DELETE FROM books WHERE bookId=%s", (bookId,)) db.commit() # Notify the user that the book has been deleted successfully print("Book deleted Successfully!") print("--------------------------") deleteBookMenu() else: print( f'The book of book id "{bookId}" does not available in the digital library.' ) print("--------------------------") deleteBookMenu() elif choice.lower() in ["no", "n"]: print("--------------------------") print("Book Not Deleted!") print("--------------------------") deleteBookMenu() else: validOption() # Update book menu options def updateBookMenu(): print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # User choices handling if userChoice == 1: home() elif userChoice == 2: updateUser() elif userChoice == 3: 16 | P a g e 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 exiting() else: validOption() def notBook(bookId): print(f'The book of book id "{bookId}" does not available in the digital library.') print("--------------------------") updateBookMenu() # Function to update book details def updateBook(): print("--------------------------") print("Update Book Details") print("--------------------------") print("1. Update the Book ID") print("2. Update the Book Name") print("3. Update the Book Publication Year") print("4. Update the Book Author Name") print("5. Home") print("6. Back") print("7. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") c.execute("SELECT bookId FROM books") result = c.fetchall() db.commit() # User choices handling if userChoice == 1: currentBookId = int(input("Enter the Current Book ID : ")) newBookId = int(input("Enter the New Book ID : ")) if (currentBookId,) in result: # Execute SQL query to update the Book ID c.execute( "UPDATE books SET bookId=%s WHERE bookId=%s", (newBookId, currentBookId) ) db.commit() print("Book ID changed Successfully!") print("--------------------------") updateBookMenu() else: notBook(currentBookId) elif userChoice == 2: bookId = int(input("Enter the Book ID : ")) newBookName = input("Enter the New Book Name : ") if (bookId,) in result: # Execute SQL query to update the Book Name c.execute( "UPDATE books SET bookName=%s WHERE bookId=%s", (newBookName, bookId) ) db.commit() print("Book Name changed Successfully!") print("--------------------------") updateBookMenu() else: 17 | P a g e 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 notBook(bookId) elif userChoice == 3: bookId = int(input("Enter the Current Book ID : ")) newPublicationYear = input("Enter the New Publication Year : ") if (bookId,) in result: # Execute SQL query to update the Publication Year c.execute( "UPDATE books SET publicationYear=%s WHERE bookId=%s", (newPublicationYear, bookId), ) db.commit() print("Book Publication Year changed Successfully!") print("--------------------------") updateBookMenu() elif userChoice == 4: bookId = int(input("Enter the Current Book ID : ")) newAuthor = input("Enter the New Author Name : ") if (bookId,) in result: # Execute SQL query to update the Author Name c.execute( "UPDATE books SET author=%s WHERE bookId=%s", (newAuthor, bookId), ) db.commit() print("Book Author Name changed Successfully!") print("--------------------------") updateBookMenu() else: notBook(bookId) elif userChoice == 5: home() elif userChoice == 6: modifyBook() elif userChoice == 7: exiting() else: validOption() # Function to display the issue book menu and handle user choices def issueBookMenu(): print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # User choices handling if userChoice == 1: home() elif userChoice == 2: admin() elif userChoice == 3: exiting() else: validOption() # Function to issue a book 18 | P a g e 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 def issueBook(): print("--------------------------") print("Issue Book") print("--------------------------") bookId = int(input("Enter the Book ID to be Issued: ")) userId = int(input("Enter the User ID to whom Book will be Issued: ")) # Execute SQL query to check the issue status of the book c.execute("SELECT userId FROM users") result1 = c.fetchall() c.execute("SELECT bookId FROM books") result2 = c.fetchall() c.execute("SELECT issueStatus FROM books WHERE bookId=%s", (bookId,)) result3 = c.fetchall() db.commit() if (userId,) in result1: if (bookId,) in result2: # Check if the book is not already issued if result3[0][0] == "not issued": # Execute SQL queries to update book details and mark it as issued c.execute( "UPDATE books SET issueDate = CURRENT_DATE WHERE bookId = %s", (bookId,), ) c.execute( "UPDATE books SET issueTime = CURRENT_TIME WHERE bookId = %s", (bookId,), ) c.execute( "UPDATE books SET issueStatus = 'issued' WHERE bookId = %s", (bookId,), ) c.execute( "UPDATE books SET returnDate = NULL WHERE bookId = %s", (bookId,) ) c.execute( "UPDATE books SET returnTime = NULL WHERE bookId = %s", (bookId,) ) c.execute( "UPDATE books SET issuedUserId = %s WHERE bookId = %s", (userId, bookId), ) db.commit() c.execute( "select issuedUserId,bookName,issueDate,issueTime from books where bookId=%s", (bookId,), ) result = c.fetchall() c.execute( "INSERT INTO issuedBooksDetails (userId, bookId,bookName,issueDate,issueTime) VALUES (%s, %s, %s, %s, %s)", (result[0][0], bookId, result[0][1], result[0][2], result[0][3]), ) db.commit() print("--------------------------") print( 19 | P a g e 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 f'Book of Book Id "{bookId}" is issued successfully to the User of User Id "{userId}".' ) print("--------------------------") returnPolicy() issueBookMenu() else: # Notify the user that the book is already issued print( f'The book of book id "{bookId}" is already issued by another user.' ) print("--------------------------") issueBookMenu() else: print( f"Book with book id {bookId} does not available in the digital library." ) print("--------------------------") issueBookMenu() else: print(f"User with user id {userId} does not exists in the digital library.") print("--------------------------") issueBookMenu() # Function to display the return book menu and handle user choices def returnBookMenu(): print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # User choices handling if userChoice == 1: home() elif userChoice == 2: admin() elif userChoice == 3: exiting() else: validOption() # Function to return a book def returnBook(): print("--------------------------") print("Return Book") print("--------------------------") bookId = int(input("Enter the Book ID to be Returned: ")) # Execute SQL query to check the issue status of the book c.execute("SELECT bookId FROM books") result1 = c.fetchall() c.execute("SELECT issueStatus FROM books WHERE bookId=%s", (bookId,)) result2 = c.fetchall() db.commit() if (bookId,) in result1: # Check if the book is issued if result2[0][0] == "issued": # Execute SQL queries to update book details and mark it as 20 | P a g e 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 returned c.execute( "UPDATE books SET returnDate = CURRENT_DATE WHERE bookId = %s", (bookId,), ) c.execute( "UPDATE books SET returnTime = CURRENT_TIME WHERE bookId = %s", (bookId,), ) c.execute( "UPDATE books SET issueStatus = 'not issued' WHERE bookId = %s", (bookId,), ) db.commit() c.execute( "select issuedUserId,returnDate,returnTime from books where bookId=%s", (bookId,), ) result = c.fetchall() c.execute( "UPDATE issuedBooksDetails SET returnDate = %s, returnTime = %s WHERE userId = %s AND bookId = %s", (result[0][1], result[0][2], result[0][0], bookId), ) db.commit() c.execute( "UPDATE books SET issuedUserId = NULL WHERE bookId = %s", (bookId,) ) db.commit() print(f'The book of book id "{bookId}" is returned successfully.') c.execute("select issueDate from books WHERE bookId = %s", (bookId,)) issueDate = c.fetchall() c.execute("select returnDate from books WHERE bookId = %s", (bookId,)) returnDate = c.fetchall() db.commit() c.execute("UPDATE %s", (bookId,)) c.execute("UPDATE %s", (bookId,)) c.execute("UPDATE %s", (bookId,)) c.execute("UPDATE %s", (bookId,)) db.commit() books SET issueDate = NULL WHERE bookId = books SET issueTime = NULL WHERE bookId = books SET returnDate = NULL WHERE bookId = books SET returnTime = NULL WHERE bookId = d1 = datetime.strptime(f"{issueDate[0][0]}", "%Y-%m-%d") d2 = datetime.strptime(f"{returnDate[0][0]}", "%Y-%m-%d") dateDifference = d1 - d2 if dateDifference.days > 14: extraDays = dateDifference.days - 14 fine = extraDays * 5 print("Fine(in Rs.) : ", fine) c.execute( 21 | P a g e 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 "update issuedBooksDetails set fineInRs=%s where userId=%s and bookId=%s", (fine, result[0][0], bookId), ) db.commit() else: fine = 0 * 5 print("Fine(in Rs.) : ", fine) c.execute( "update issuedBooksDetails set fineInRs=%s where userId=%s and bookId=%s", (fine, result[0][0], bookId), ) db.commit() print("--------------------------") returnBookMenu() else: # Notify the user that the book is not issued print(f'The book of book id "{bookId}" is not issued by any user.') print("--------------------------") returnBookMenu() else: print(f"Book with book id {bookId} does not available in the digital library.") print("--------------------------") returnBookMenu() # Function to display the add user menu and handle user choices def addUserMenu(): # Add user menu options print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # User choices handling if userChoice == 1: home() elif userChoice == 2: modifyUser() elif userChoice == 3: exiting() else: validOption() # Function to add a new user def addUser(): print("--------------------------") print("Add User") print("--------------------------") # Get user input for user details userId = int(input("Enter the User ID : ")) userName = input("Enter the User Name : ") userPhoneNumber = input("Enter the User Phone Number : ") userEmailId = input("Enter the User Email ID : ") password = input("Enter the User Password : ") print("--------------------------") c.execute("SELECT userId FROM users") result = c.fetchall() db.commit() 22 | P a g e 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 if (userId,) in result: print( f'The user of user number "{userId}" is already enrolled in the digital library.' ) print("--------------------------") addUserMenu() else: # Execute SQL query to insert the new user into the database c.execute( "INSERT INTO users (userId, userName, phoneNumber, emailId, password) VALUES (%s, %s, %s, %s, %s)", (userId, userName, userPhoneNumber, userEmailId, password), ) db.commit() # Notify the user that the user has been added successfully print("--------------------------") print("User added successfully!") print("--------------------------") addUserMenu() # Function to display the delete user menu and handle user choices def deleteUserMenu(): # Delete user menu options print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # User choices handling if userChoice == 1: home() elif userChoice == 2: modifyUser() elif userChoice == 3: exiting() else: validOption() # Function to delete a user def deleteUser(): print("--------------------------") print("Delete User") print("--------------------------") # Get user input for the user ID to be deleted userId = int(input("Enter the User ID : ")) choice = input("Are you sure to delete the User? (Yes/No) : ") c.execute("SELECT userId FROM users") result = c.fetchall() db.commit() if choice.lower() in ["yes", "y"]: if (userId,) in result: c.execute("DELETE FROM users WHERE userId=%s", (userId,)) db.commit() # Notify the user that the user has been deleted successfully print("User deleted successfully!") print("--------------------------") deleteUserMenu() 23 | P a g e 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 else: print( f'The user of user id "{userId}" does not enrolled in the digital library.' ) print("--------------------------") deleteUserMenu() elif choice.lower() in ["no", "n"]: print("--------------------------") print("User Not Deleted!") print("--------------------------") deleteUserMenu() else: validOption() # Function to display the update user menu and handle user choices def updateUserMenu(): print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) # User choices handling if userChoice == 1: home() elif userChoice == 2: updateUser() elif userChoice == 3: exiting() else: validOption() def notUser(userId): print(f'The user of user id "{userId}" does not enrolled in the digital library.') print("--------------------------") updateBookMenu() # Function to update user details def updateUser(): print("--------------------------") print("Update User Details") print("--------------------------") # Display user update options print("1. Update the User ID") print("2. Update the User Name") print("3. Update the User Phone Number") print("4. Update the User Email ID") print("5. Update the User Password") print("6. Home") print("7. Back") print("8. Exit") # Get user choice userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") c.execute("SELECT userId FROM users") result = c.fetchall() db.commit() if userChoice == 1: # Update user ID currentUserId = int(input("Enter the Current User ID : ")) 24 | P a g e 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 newUserId = int(input("Enter the New User ID : ")) if (currentUserId,) in result: c.execute( "update users set userId=%s where userId=%s", (newUserId, currentUserId) ) db.commit() print("User ID changed Successfully!") print("--------------------------") updateUserMenu() else: notUser(currentUserId) elif userChoice == 2: # Update user name userId = int(input("Enter the User ID : ")) newUserName = input("Enter the New User Name : ") if (userId,) in result: c.execute( "update users set userName=%s where userId=%s", (newUserName, userId) ) db.commit() print("User Name changed Successfully!") print("--------------------------") updateUserMenu() else: notUser(userId) elif userChoice == 3: # Update user phone number userId = int(input("Enter the Current User ID : ")) newPhoneNumber = input("Enter the New Phone Number : ") if (userId,) in result: c.execute( "update users set phoneNumber=%s where userId=%s", (newPhoneNumber, userId), ) db.commit() print("User Phone Number changed Successfully!") print("--------------------------") updateUserMenu() else: notUser(userId) elif userChoice == 4: # Update user email ID userId = int(input("Enter the Current User ID : ")) newEmailId = input("Enter the New Email ID : ") if (userId,) in result: c.execute( "update users set emailId=%s where userId=%s", (newEmailId, userId) ) db.commit() print("User Email ID changed Successfully!") print("--------------------------") updateUserMenu() 25 | P a g e 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 else: notUser(userId) elif userChoice == 5: # Update user password userId = int(input("Enter the Current User ID : ")) newPassword = input("Enter the New Password : ") if (userId,) in result: c.execute( "update users set password=%s where userId=%s", (newPassword, userId) ) db.commit() print("User Password changed Successfully!") print("--------------------------") updateUserMenu() else: notUser(userId) elif userChoice == 6: # Return to home home() elif userChoice == 7: # Go back to the previous menu modifyUser() elif userChoice == 8: # Exit the program exiting() else: validOption() # Function to modify user def modifyUser(): print("--------------------------") print("Modify User") print("--------------------------") # Display user modification options print("1. Add User") print("2. Delete User") print("3. Update User Details") print("4. Home") print("5. Back") print("6. Exit") # Get user choice userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # User choices handling if userChoice == 1: # Add a new user addUser() elif userChoice == 2: # Delete a user deleteUser() elif userChoice == 3: # Update user details updateUser() elif userChoice == 4: # Return to home home() elif userChoice == 5: # Return to the previous menu admin() elif userChoice == 6: 26 | P a g e 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 # Exit the program exiting() else: validOption() # Display users menu options def displayUsersMenu(): print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) # User choices handling if userChoice == 1: home() elif userChoice == 2: admin() elif userChoice == 3: exiting() else: validOption() # Function to display all users def displayUsers(): print("--------------------------") print("Display Users") print("--------------------------") # Fetch all users from the database c.execute("SELECT * FROM users ORDER BY userId") result = c.fetchall() db.commit() if result: # Display user information print("Users enrolled in the Digital Library are :") i = 0 for row in result: i += 1 r = length(i) print(f"{i}. User ID : {row[0]}") print(" " * r + f"User Name : {row[1]}") print(" " * r + f"Phone Number : {row[2]}") print(" " * r + f"Email ID : {row[3]}") print(" " * r + f"Admin Status : {row[5]}") print("--------------------------") displayUsersMenu() else: print("No users found.") print("--------------------------") displayUsersMenu() # Search user menu options def searchUsersMenu(): print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) # User choices handling if userChoice == 1: home() elif userChoice == 2: 27 | P a g e 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 searchUsers() elif userChoice == 3: exiting() else: validOption() # Function to search users by ID def searchUsersbyId(): print("--------------------------") print("Search Users by User ID") print("--------------------------") # Get user ID to search userId = int(input("Enter the User ID to search the User : ")) # Search for the user in the database c.execute("SELECT * FROM users WHERE userId=%s", (userId,)) result = c.fetchall() db.commit() if result: # Display user information if found print(f'User enrolled in the Digital Library with the User ID "{userId}" is :') i = 0 for row in result: i += 1 r = length(i) print(f"{i}. User ID : {row[0]}") print(" " * r + f"User Name : {row[1]}") print(" " * r + f"Phone Number : {row[2]}") print(" " * r + f"Email ID : {row[3]}") print(" " * r + f"Admin Status : {row[5]}") print("--------------------------") searchUsersMenu() else: # Handle case when no user is found print(f'No user found with the user id "{userId}".') print("--------------------------") searchUsersMenu() # Function to search users by keyword def searchUsersbyKeyword(): print("--------------------------") print("Search Users by Keyword") print("--------------------------") # Get keyword input from the user keyword = input("Enter a Keyword to search Users : ") # Search for users with the given keyword in their names c.execute( "SELECT * FROM users WHERE userName LIKE '%{}%' ORDER BY userId".format(keyword) ) result = c.fetchall() db.commit() if result: # Display user information if users are found print( f'Users enrolled in the Digital Library with the Keyword "{keyword}" are :' ) i = 0 28 | P a g e 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 for row in result: i += 1 r = length(i) print(f"{i}. User ID : {row[0]}") print(" " * r + f"User Name : {row[1]}") print(" " * r + f"Phone Number : {row[2]}") print(" " * r + f"Email ID : {row[3]}") print(" " * r + f"Admin Status : {row[5]}") print("--------------------------") searchUsersMenu() else: # Handle case when no user is found print(f'No users found with the keyword "{keyword}".') print("--------------------------") searchUsersMenu() # Function to search users def searchUsers(): print("--------------------------") print("Search Users") print("--------------------------") # User search menu print("1. Search by User ID") print("2. Search by Keyword") print("3. Home") print("4. Back") print("5. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # User choices handling if userChoice == 1: searchUsersbyId() elif userChoice == 2: searchUsersbyKeyword() elif userChoice == 3: home() elif userChoice == 4: admin() elif userChoice == 5: exiting() else: validOption() # Function to modify books def modifyBook(): print("--------------------------") print("Modify Book") print("--------------------------") # Book modification menu print("1. Add Book") print("2. Delete Book") print("3. Update Book Details") print("4. Home") print("5. Back") print("6. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # User choices handling if userChoice == 1: addBook() elif userChoice == 2: 29 | P a g e 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 deleteBook() elif userChoice == updateBook() elif userChoice == home() elif userChoice == admin() elif userChoice == exiting() else: validOption() 3: 4: 5: 6: # Function to manage notes def notes(): print("--------------------------") print("Notes") print("--------------------------") # Display menu options print("1. Modify Note") print("2. Display Notes") print("3. Search Notes") print("4. Home") print("5. Back") print("6. Exit") # Get user choice userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: modifyNote() elif userChoice == 2: displayNotes() elif userChoice == 3: searchNotes() elif userChoice == 4: home() elif userChoice == 5: user() elif userChoice == 6: exiting() else: validOption() # Function to display the add note menu and handle user choices def addNoteMenu(): print("1. Home") print("2. Back") print("3. Exit") # Get user choice userChoice = int(input("Enter your Choice to Continue : ")) # Handle user choices if userChoice == 1: home() elif userChoice == 2: modifyNote() elif userChoice == 3: exiting() else: validOption() # Function to add note 30 | P a g e 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 def addNote(): print("--------------------------") print("Add Note") print("--------------------------") # Get note details from the user noteNumber = int(input("Enter the Note Number : ")) noteTitle = input("Enter the Note Title : ") noteDescription = input("Enter the Note Description : ") print("--------------------------") c.execute("SELECT noteNumber FROM notes where userId=%s", (USERID,)) result = c.fetchall() db.commit() if (noteNumber,) in result: print( f'The note of note number "{noteNumber}" is already exists in the digital library.' ) print("--------------------------") addNoteMenu() else: # Execute SQL query to insert the note into the database c.execute( "INSERT INTO notes (userId, noteNumber, noteTitle, noteDescription, updateDate, updateTime) VALUES (%s, %s, %s, %s, CURRENT_DATE, CURRENT_TIME)", (USERID, noteNumber, noteTitle, noteDescription), ) db.commit() print(f'The note of note number "{noteNumber}" is added successfully.') print("--------------------------") addNoteMenu() # Function to display the delete note menu and handle user choices def deleteNoteMenu(): # Display menu options after deleting the note print("1. Home") print("2. Back") print("3. Exit") # Get user choice userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: home() elif userChoice == 2: modifyNote() elif userChoice == 3: exiting() else: validOption() # Function to delete a note def deleteNote(): print("--------------------------") print("Delete Note") print("--------------------------") # Get note number to be deleted from the user noteNumber = int(input("Enter the Note Number to Delete the Note : ")) 31 | P a g e 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 choice = input("Are you sure to delete the Note? (Yes/No) : ") print("--------------------------") c.execute("SELECT noteNumber FROM notes where userId=%s", (USERID,)) result = c.fetchall() db.commit() if choice.lower() in ["yes", "y"]: if (noteNumber,) in result: # Execute SQL query to delete the note from the database c.execute( "delete FROM notes WHERE userId=%s and noteNumber=%s", (USERID, noteNumber), ) db.commit() print(f'The note of note number "{noteNumber}" is deleted successfully.') print("--------------------------") deleteNoteMenu() else: print( f'The note of note number "{noteNumber}" does not exists in the digital library.' ) print("--------------------------") deleteNoteMenu() elif choice.lower() in ["no", "n"]: print("--------------------------") print("Note Not Deleted!") print("--------------------------") deleteNoteMenu() else: validOption() # Function to display the update notes menu and handle user choices def updateNotesMenu(): print("1. Home") print("2. Back") print("3. Exit") # Get user choice userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: home() elif userChoice == 2: updateNotes() elif userChoice == 3: exiting() else: validOption() def notNote(noteNumber): print( f'The note of note number "{noteNumber}" does not exists in the digital library.' ) print("--------------------------") updateNotesMenu() 32 | P a g e 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 # Function to update a note def updateNotes(): print("--------------------------") print("Update Notes") print("--------------------------") # Display update options print("1. Update the Note Number") print("2. Update the Note Title") print("3. Update the Note Description") print("4. Home") print("5. Back") print("6. Exit") # Get user choice userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") c.execute("SELECT noteNumber FROM notes where userId=%s", (USERID,)) result = c.fetchall() db.commit() # Handle user choices if userChoice == 1: # Update Note Number currentNoteNumber = int(input("Enter the Current Note Number : ")) newNoteNumber = int(input("Enter the New Note Number : ")) if (currentNoteNumber,) in result: # Update date and time c.execute( "update notes set updateDate=CURRENT_DATE where userId=%s and noteNumber=%s", (USERID, currentNoteNumber), ) c.execute( "update notes set updateTime=CURRENT_TIME where userId=%s and noteNumber=%s", (USERID, currentNoteNumber), ) # Update Note Number c.execute( "update notes set noteNumber=%s where userId=%s and noteNumber=%s", (newNoteNumber, USERID, currentNoteNumber), ) db.commit() print("Note Number changed Successfully!") print("--------------------------") updateNotesMenu() else: notNote(currentNoteNumber) elif userChoice == 2: # Update Note Title noteNumber = int(input("Enter the Current Note Number : ")) newTitle = input("Enter the New Note Title : ") if (noteNumber,) in result: # Update date and time c.execute( "update notes set updateDate=CURRENT_DATE where userId=%s and noteNumber=%s", (USERID, noteNumber), ) c.execute( "update notes set updateTime=CURRENT_TIME where userId=%s 33 | P a g e 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 and noteNumber=%s", (USERID, noteNumber), ) # Update Note Title c.execute( "update notes set noteTitle=%s where userId=%s and noteNumber=%s", (newTitle, USERID, noteNumber), ) db.commit() print("Note Title changed Successfully!") print("--------------------------") updateNotesMenu() else: notNote(noteNumber) elif userChoice == 3: # Update Note Description noteNumber = int(input("Enter the Current Note Number : ")) newDescription = input("Enter the New Note Description : ") if (noteNumber,) in result: # Update date and time c.execute( "update notes set updateDate=CURRENT_DATE where userId=%s and noteNumber=%s", (USERID, noteNumber), ) c.execute( "update notes set updateTime=CURRENT_TIME where userId=%s and noteNumber=%s", (USERID, noteNumber), ) # Update Note Description c.execute( "update notes set noteDescription=%s where userId=%s and noteNumber=%s", (newDescription, USERID, noteNumber), ) db.commit() print("Note Description changed successfully!") print("--------------------------") updateNotesMenu() else: notNote(noteNumber) elif userChoice == 5: home() elif userChoice == 6: modifyNote() elif userChoice == 7: exiting() else: validOption() # Function to handle note modifications def modifyNote(): print("--------------------------") print("Modify Notes") print("--------------------------") # Display modification options print("1. Add Note") print("2. Delete Note") 34 | P a g e 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 print("3. Update Notes") print("4. Home") print("5. Back") print("6. Exit") # Get user choice userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: addNote() elif userChoice == 2: deleteNote() elif userChoice == 3: updateNotes() elif userChoice == 4: home() elif userChoice == 5: admin() elif userChoice == 6: exiting() else: validOption() # Function to display the display notes menu and handle user choices def displayNotesMenu(): print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: home() elif userChoice == 2: user() elif userChoice == 3: exiting() else: validOption() # Function to display notes def displayNotes(): # Fetch all notes from the database c.execute("SELECT * FROM notes ORDER BY noteNumber") result = c.fetchall() db.commit() # Check if there are notes available if result: print(f"Notes available in the Digital Library are :") i = 0 for row in result: i += 1 r = length(i) print(f"{i}. Note Number : {row[1]}") print(" " * r + f"Note Title : {row[2]}") print(" " * r + f"Note Description : {row[3]}") print(" " * r + f"Update Date : {row[4]}") print(" " * r + f"Update Time : {row[5]}") print("--------------------------") displayNotesMenu() 35 | P a g e 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 else: # If no notes are found print("No notes found.") print("--------------------------") displayNotesMenu() # Function to display the search notes menu and handle user choices def searchNotesMenu(): print("1. Home") print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) # Handle user choices if userChoice == 1: home() elif userChoice == 2: searchNotes() elif userChoice == 3: exiting() else: validOption() # Function to search notes by note number def searchNotesbynoteNumber(): # Get the note number to search noteNumber = int(input("Enter the Note Number to search the Note : ")) # Execute SQL query to fetch notes with the given note number c.execute("SELECT * FROM notes WHERE bookId=%s", (noteNumber,)) result = c.fetchall() db.commit() # Check if notes are found if result: print( f'Note available in the Digital Library with the Note Number "{noteNumber}" is :' ) i = 0 for row in result: i += 1 r = length(i) print(f"{i}. Note Number : {row[1]}") print(" " * r + f"Note Title : {row[2]}") print(" " * r + f"Note Description : {row[3]}") print("--------------------------") searchNotesMenu() else: # If no notes are found with the given note number print(f'No note found with the note number "{noteNumber}".') print("--------------------------") searchNotesMenu() # Function to search notes by keyword def searchNotesbyKeyword(): print("--------------------------") print("Search Notes by Keyword") print("--------------------------") # Get keyword from user keyword = input("Enter a Keyword to search Notes : ") 36 | P a g e 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 # Execute SQL query to fetch notes with the given keyword in the title c.execute( "SELECT * FROM notes WHERE noteTitle LIKE '%{}%' ORDER BY noteNumber".format( keyword ) ) result = c.fetchall() db.commit() # Check if notes are found if result: print( f'Notes available in the Digital Library with the Keyword "{keyword}" are :' ) i = 0 for row in result: i += 1 r = length(i) print(f"{i}. Note Number : {row[1]}") print(" " * r + f"Note Title : {row[2]}") print(" " * r + f"Note Description : {row[3]}") print("--------------------------") searchNotesMenu() else: # If no notes are found with the given keyword print(f'No notes found with the keyword "{keyword}".') print("--------------------------") searchNotesMenu() # Function to handle note searching def searchNotes(): print("--------------------------") print("Search Notes") print("--------------------------") # Display search options print("1. Search by Note Number") print("2. Search by Keyword") print("3. Home") print("4. Back") print("5. Exit") # Get user choice userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: searchNotesbynoteNumber() elif userChoice == 2: searchNotesbyKeyword() elif userChoice == 3: notes() elif userChoice == 4: modifyNote() elif userChoice == 5: exiting() else: validOption() # Function to display the change admin menu and handle user choices def changeAdminMenu(): print("1. Home") 37 | P a g e 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 print("2. Back") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: home() elif userChoice == 2: admin() elif userChoice == 3: exiting() else: validOption() # Function to change the admin status def changeAdmin(): print("--------------------------") print("Change Admin") print("--------------------------") # Get new admin's ID and password from the user newAdminId = int(input("Enter the New Admin's User ID : ")) newAdminPassword = input("Enter the New Admin's Password : ") choice = input("Are you sure to change the Admin? (Yes/No) : ") print("--------------------------") # Check if the entered user ID exists c.execute("SELECT password FROM users WHERE userId=%s", (newAdminId,)) result = c.fetchall() db.commit() # Check the user's choice to proceed or cancel if choice.lower() in ["yes", "y"]: # If the user ID is not valid, print an error message if len(result) == 0: print("Please enter a valid user id!") else: # If the entered password matches the user's password if newAdminPassword == result[0][0]: # Update admin status for all users c.execute( "UPDATE users SET adminStatus='not admin' WHERE adminStatus ='admin'" ) c.execute( "UPDATE users SET adminStatus='admin' WHERE userId =%s", (newAdminId,), ) db.commit() print("Admin Changed Successfully!") print("--------------------------") changeAdminMenu() else: print("Please enter a valid password!") elif choice.lower() in ["no", "n"]: print("Admin Not Changed!") print("--------------------------") changeAdminMenu() else: validOption() 38 | P a g e 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 # Function to authenticate admin def authAdmin(): print("--------------------------") print("Admin Authentication") print("--------------------------") adminId = int(input("Enter the Admin's User ID : ")) adminPassword = input("Enter the Admin's User Password : ") # Check if the entered admin ID exists c.execute("SELECT password FROM users WHERE userId=%s", (adminId,)) result = c.fetchall() db.commit() # If the entered admin ID is not valid, print an error message if len(result) == 0: print("--------------------------") print("Please enter a valid user id!") print("--------------------------") else: # If the entered password matches the admin's password if adminPassword == result[0][0]: global USERID USERID = adminId print("\033[0;35m--------------------------\033[0;0m") print("\033[0;36mAdmin is verified successfully.\033[0;0m") print("\033[0;35m--------------------------\033[0;0m") admin() # Call the admin menu else: print("Please enter a valid password!") print("--------------------------") # Function to display the admin menu def admin(): print("--------------------------") print("Admin") print("--------------------------") print("1. Login into User Panel") print("2. Modify User") print("3. Display Users") print("4. Search Users") print("5. Modify Book") print("6. Issue Book") print("7. Return Book") print("8. Change Admin") print("9. Home") print("10. Back") print("11. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: print("You are successfully login into user panel.") print("--------------------------") user() elif userChoice == modifyUser() elif userChoice == displayUsers() elif userChoice == searchUsers() elif userChoice == modifyBook() elif userChoice == 2: 3: 4: 5: 6: 39 | P a g e 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 issueBook() elif userChoice == returnBook() elif userChoice == changeAdmin() elif userChoice == home() elif userChoice == authAdmin() elif userChoice == exiting() else: validOption() 7: 8: 9: 10: 11: # Function to authenticate a user def authUser(): print("--------------------------") print("User Authentication") print("--------------------------") userId = int(input("Enter the User ID : ")) password = input("Enter the User Password : ") # Check if the entered user ID exists c.execute("SELECT password FROM users WHERE userId=%s", (userId,)) result = c.fetchall() db.commit() # If the entered user ID is not valid, print an error message if len(result) == 0: print("--------------------------") print("Please enter a valid user id!") print("--------------------------") else: # If the entered password matches the user's password if password == result[0][0]: global USERID USERID = userId print("\033[0;35m--------------------------\033[0;0m") print("\033[0;36mUser is verified successfully.\033[0;0m") print("\033[0;35m--------------------------\033[0;0m") user() # Call the user menu else: print("Please Enter a Valid Password!") print("--------------------------") # Function to search & display the wikipedia articles def wikipediaArticles(): # Function to fetch article details def fetchingArticle(keyword, articleLength=1500): # Creating a Wikipedia API object wiki = wikipediaapi.Wikipedia(language="en", user_agent="digitallibrary/1.1") # Fetching the page for the given search query page = wiki.page(keyword) # Checking if the page exists if not page.exists(): print( f'Sorry, the Wikipedia Article for the keyword "{keyword}" does not exists.' ) print("--------------------------") else: # Displaying article title 40 | P a g e 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 print("Title : ") print(page.title) print("URL : ") print(page.fullurl) # Displaying a summary of the article within the specified length print("Summary : ") start = 0 end = 157 article = page.summary[:articleLength] while end <= articleLength: print(article[start:end]) start += 157 end += 157 else: print("--------------------------") print("--------------------------") print("Search Articles") print("--------------------------") # Taking user input for the keyword and article length keyword = input("Enter the Keyword for searching the Wikipedia Article : ") articleLength = int(input("Enter the Article Length : ")) print("--------------------------") # Calling the function to fetch and display the article fetchingArticle(keyword, articleLength) userMenu() # Function to search & display the news def news(): def fetchNews(apiKey, country="in", category="science", numArticles=5): url = f"https://newsapi.org/v2/top-headlines" params = { "apiKey": apiKey, "country": country, "category": category, "pageSize": numArticles, } response = requests.get(url, params=params) if response.status_code == 200: news_data = response.json() articles = news_data.get("articles", []) for i, article in enumerate(articles, start=1): print(f"{i}. {article['title']}") print(f" Source: {article['source']['name']}") print(f" URL: {article['url']}") print("--------------------------") else: print(f"Error {response.status_code}: {response.text}") print("--------------------------") API_KEY = "YOUR_API_KEY" print("--------------------------") print("News") print("--------------------------") print("Country codes are : ") 41 | P a g e 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 print("https://newsapi.org/sources") print("Categories are : ") print("business, entertainment, general, health, science, sports, technology") print("--------------------------") country = input("Enter the Country Code : ") category = input("Enter the Category : ") numArticles = int(input("Enter the Number of Articles : ")) print("--------------------------") fetchNews(API_KEY, country, category, numArticles) userMenu() # Function to display the issued books details of a user def issuedBooksDetails(): print("--------------------------") print("Issued Books Details") print("--------------------------") returnPolicy() c.execute( "SELECT * FROM issuedBooksDetails WHERE userId=%s ORDER BY bookId", (USERID,) ) result = c.fetchall() db.commit() if result == []: print("No Books Issued!") print("--------------------------") userMenu() else: i = 0 for row in result: i += 1 r = length(i) print(f"{i}. Book ID : ", row[1]) print(" " * r + "Book Name : ", row[2]) print(" " * r + "Issue Date : ", row[3]) print(" " * r + "Issue Time : ", row[4]) print(" " * r + "Return Date : ", row[5]) print(" " * r + "Return Time : ", row[6]) print(" " * r + "Fine(in Rs.) : ", row[7]) print("--------------------------") userMenu() # Function to display the user menu def user(): print("--------------------------") print("User") print("--------------------------") # Check if the entered user ID exists c.execute('SELECT userId FROM users WHERE adminStatus="admin"') result = c.fetchall() db.commit() if result[0][0] == USERID: print("1. Login into Admin Panel") print("2. About the Library") print("3. News") print("4. Wikipedia Articles") print("5. Display Books") 42 | P a g e 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 print("6. Search Books") print("7. Issued Books Details") print("8. Notes") print("9. Home") print("10. Back") print("11. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: print("You are successfully login into admin panel.") print("--------------------------") admin() elif userChoice == 2: aboutLibrary() elif userChoice == 3: news() elif userChoice == 4: wikipediaArticles() elif userChoice == 5: displayBooks() elif userChoice == 6: searchBooks() elif userChoice == 7: issuedBooksDetails() elif userChoice == 8: notes() elif userChoice == 9: home() elif userChoice == 10: authUser() elif userChoice == 11: exiting() else: validOption() else: print("1. About Library") print("2. News") print("3. Wikipedia Articles") print("4. Display Books") print("5. Search Books") print("6. Issued Books Details") print("7. Notes") print("8. Home") print("9. Back") print("10. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: aboutLibrary() elif userChoice == 2: news() elif userChoice == 3: wikipediaArticles() elif userChoice == 4: displayBooks() elif userChoice == 5: searchBooks() elif userChoice == 6: issuedBooksDetails() elif userChoice == 7: notes() 43 | P a g e 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 elif userChoice == 8: home() elif userChoice == 9: authUser() elif userChoice == 10: exiting() else: validOption() # Function to display the main menu def home(): while True: print("==========================") print("\033[1;32m~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0;0m") print( "\033[1;31m" + pyfiglet.figlet_format("Welcome to the", font="banner3", width=1000) ) print( pyfiglet.figlet_format("Digital Library", font="banner3", width=1000) + "\033[0;0m" ) print("\033[1;32m~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0;0m") print("==========================") print("--------------------------") print("Home") print("--------------------------") print("1. Admin") print("2. User") print("3. Exit") userChoice = int(input("Enter your Choice to Continue : ")) print("--------------------------") # Handle user choices if userChoice == 1: authAdmin() elif userChoice == 2: authUser() elif userChoice == 3: exiting() else: validOption() # Call the main menu function home() 44 | P a g e MySQL Database 45 | P a g e Library Database: Books Table: Users Table: 46 | P a g e Notes Table: Issued Books Details Table: 47 | P a g e Outputs 48 | P a g e Starting of the program: Admin Authentication: Adding a new user: 49 | P a g e Updating user details: Adding a new book: 50 | P a g e Updating book details: 51 | P a g e User Authentication: About Library: 52 | P a g e News: Wikipedia Articles: 53 | P a g e Issued Books Details: 54 | P a g e Existing the program: 55 | P a g e REFERENCES 1. News API https://newsapi.org/ 2. Wikipedia https://www.wikipedia.org/ 3. Python https://www.python.org/ 4. MySQL https://www.mysql.com/ 5. ANSI Escape Codes in Python https://pypi.org/project/ansi/ https://replit.com/talk/learn/ANSI-Escape-Codes-inPython/22803 https://gist.github.com/rened/9e584a7dd2935d0f461904b9f2950007 6. Class 11th & 12th Computer Science Arihant Books 56 | P a g e

Formatting page ...

Related ResPapers
Maharashtra Board Class 9 Exam 2025 : Chemistry
by utsa86 

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

 

  Print intermediate debugging step

Show debugging info


 

 


© 2010 - 2025 ResPaper. Terms of ServiceContact Us Advertise with us

 

utsa86 chat