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