Digital Library
Digital Library
SCHOOL,JATNI,KHORDHA,ODISHA
Submitted by:
Name: Abhisek Sahoo
Class: XII (SCIENCE)
Roll Number:
Under the Guidance of:
Ms. Chinmayee Nayak
PGT (CS)
CARMEL ENGLISH MEDIUM SCHOOL
CARMEL ENGLISH MEDIUM
SCHOOL,JATNI,KHORDHA,ODISHA
CERTIFICATE
1|Page
TABLE OF CONTENTS
2|Page
ACKNOWLEDGMENT
Apart from the efforts of me, the success of any project depends largely on the
encouragement and guidelines of many others. I take this opportunity to express my
gratitude to the people who have been instrumental in the successful completion of this
project.
I express deep sense of gratitude to almighty God for giving me strength for the
successful completion of the project.
I express my deep sense of gratitude to the luminary The Principal, Carmel English
Medium School, Khordha, who has been continuously motivating and extending their
helping hand to us.
I express my sincere thanks to the academician The Vice Principal, Carmel English
Medium school, Khordha for constant encouragement and the guidance provided during
this project
My sincere thanks to Ms. Chinmayee Nayak (PGT),,A guide, Mentor all the above a
friend who critically reviewed my project and helped in solving each and every problem,
occurred during implementation of the project.
The guidance and support received from all the members who contributed and who
are contributing to this proiect, was vital for the success of the project. I am grateful for
their constant support and help.
3|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
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 cost-
effective. 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 # Importing necessary libraries
2 import mysql.connector
3 import pyfiglet
4 import requests
5 import wikipediaapi
6 from datetime import datetime
7
8
9 # Connect to the MySQL database
10 db = mysql.connector.connect(
11 host="localhost",
12 user="root",
13 password="admin",
14 database="library",
15 )
16 c = db.cursor()
17
18
19 # Function to display the return policy information
20 def returnPolicy():
21 print("Return Policy : ")
22 print("The issued book should be returned within 14 days(2 weeks).")
23 print(
24 "If the user kept the issued book for more than 14 days, then the
25 user have to pay ₹5 as fine for each extra day the user kept the issued
26 book."
27 )
28 print(" ")
29
30
31 # Function to calculate the length of a given integer after converting it
32 to a string
33 def length(i):
34 s = str(i)
35 length = len(s) + 2
36
37 return length
38
39
40 # Function to display a message for an invalid option
41 def validOption():
42 print("Please enter a valid option!")
43 print(" ")
44
45
46 # Function to handle program exit
47 def exiting():
48 print("\033[3;34m--------------------------\033[0;0m")
49 print("\033[3;33mExiting the program.")
50 print("Thank You!\033[0;0m")
51 print("\033[3;34m--------------------------\033[0;0m")
52 exit()
53
54
55 # Function to display the user menu and handle user choices
56 def userMenu():
57 # Displaying options for the user
58 print("1. Add Note")
59 print("2. Home")
60 print("3. Back")
61 print("4. Exit")
62 # Taking user choice as input
63 userChoice = int(input("Enter your Choice to Continue : "))
64 print(" ")
65
66 # Handle user choices
11 | P a g e
67 if userChoice == 1:
68 addNote()
69 elif userChoice == 2:
70 home()
71 elif userChoice == 3:
72 user()
73 elif userChoice == 4:
74 exiting()
75 else:
76 validOption()
77
78
79 # Function to display information about the library
80 def aboutLibrary():
81 # Retrieve the name of the librarian who is also an admin
82 c.execute("SELECT userName FROM users WHERE adminStatus='admin'")
83 userName = c.fetchall()
84
85 # Retrieve the total number of books and users in the library
86 c.execute("SELECT * FROM books")
87 totalBooks = c.fetchall()
88
89 c.execute("SELECT * FROM users")
90 totalUsers = c.fetchall()
91 db.commit()
92
93 print(" ")
94 print("About Library")
95 print(" ")
96 # Display library information
97 print("Year of Library's Establishment : ", 2023)
98 print("Name of the Librarian : ", userName[0][0])
99 print("Total Number of Books Available in the Library : ",
100 len(totalBooks))
101 print("Total Number of Users Enrolled in the Library : ",
102 len(totalUsers))
103 print(" ")
104 userMenu()
105
106
107 # Function to display the list of books in the library
108 def displayBooks():
109 print(" ")
110 print("Display Books")
111 print(" ")
112 # Retrieve all books from the database
113 c.execute("SELECT * FROM books ORDER BY bookId")
114 result = c.fetchall()
115 db.commit()
116
117 # Display books if available, otherwise notify the user
118 if result:
119 print("Books available in the Digital Library are :")
120 print(" ")
121 i = 0
122 for row in result:
123 i += 1
124 r = length(i)
125 print(f"{i}. Book ID : {row[0]}")
126 print(" " * r + f"Book Name : {row[1]}")
127 print(" " * r + f"Publication Year : {row[2]}")
128 print(" " * r + f"Author Name : {row[7]}")
129 print(" " * r + f"Issue Status : {row[8]}")
130 print("--------------------------")
131 userMenu()
132 else:
12 | P a g e
133 # Notify the user if no books are found
134 print("No books found.")
135 print("--------------------------")
136 userMenu()
137
138
139 # Search books menu options
140 def searchBooksMenu():
141 print("1. Add Note")
142 print("2. Home")
143 print("3. Back")
144 print("4. Exit")
145 userChoice = int(input("Enter your Choice to Continue : "))
146
147 # User choices handling
148 if userChoice == 1:
149 addNote()
150 elif userChoice == 2:
151 home()
152 elif userChoice == 3:
153 searchBooks()
154 elif userChoice == 4:
155 exiting()
156 else:
157 validOption()
158
159
160 # Function to search books by Book ID
161 def searchBooksbyId():
162 print(" ")
163 print("Search Books by Book ID")
164 print(" ")
165 # Get user input for Book ID
166 bookId = int(input("Enter the Book ID to search the Book : "))
167 print(" ")
168
169 # Execute SQL query to retrieve book information by Book ID
170 c.execute("SELECT * FROM books WHERE bookId=%s", (bookId,))
171 result = c.fetchall()
172 db.commit()
173
174 # Display search results if books are found, otherwise notify the user
175 if result:
176 print(f'Book available in the Digital Library with the Book ID
177 "{bookId}" is :')
178 print(" ")
179 i = 0
180 for row in result:
181 i += 1
182 r = length(i)
183 print(f"{i}. Book ID : {row[0]}")
184 print(" " * r + f"Book Name : {row[1]}")
185 print(" " * r + f"Publication Year : {row[2]}")
186 print(" " * r + f"Author Name : {row[7]}")
187 print(" " * r + f"Issue Status : {row[8]}")
188 print("--------------------------")
189 searchBooksMenu()
190 else:
191 print(f'No book found with the book id "{bookId}".')
192 print(" ")
193 searchBooksMenu()
194
195
196 # Function to search books by keyword
197 def searchBooksbyKeyword():
198 print(" ")
13 | P a g e
199 print("Search Books by Keyword")
200 print(" ")
201 # Get user input for keyword
202 keyword = input("Enter a Keyword to search Books : ")
203 print(" ")
204
205 # Execute SQL query to retrieve books by keyword
206 c.execute(
207 "SELECT * FROM books WHERE bookName LIKE '%{}%' ORDER BY
208 bookId".format(keyword)
209 )
210 result = c.fetchall()
211 db.commit()
212
213 # Display search results if books are found, otherwise notify the user
214 if result:
215 print(
216 f'Books available in the Digital Library with the Keyword
217 "{keyword}" are :'
218 )
219 print(" ")
220 i = 0
221 for row in result:
222 i += 1
223 r = length(i)
224 print(f"{i}. Book ID : {row[0]}")
225 print(" " * r + f"Book Name : {row[1]}")
226 print(" " * r + f"Publication Year : {row[2]}")
227 print(" " * r + f"Author Name : {row[7]}")
228 print(" " * r + f"Issue Status : {row[8]}")
229 print("--------------------------")
230 searchBooksMenu()
231 else:
232 print(f'No books found with the keyword "{keyword}".')
233 print(" ")
234 searchBooksMenu()
235
236
237 # Function to display search options for books
238 def searchBooks():
239 print(" ")
240 print("Search Books")
241 print(" ")
242 print("1. Search by Book ID")
243 print("2. Search by Keyword")
244 print("3. Home")
245 print("4. Back")
246 print("5. Exit")
247 userChoice = int(input("Enter your Choice to Continue : "))
248 print(" ")
249
250 # User choices handling
251 if userChoice == 1:
252 searchBooksbyId()
253 elif userChoice == 2:
254 searchBooksbyKeyword()
255 elif userChoice == 3:
256 home()
257 elif userChoice == 4:
258 user()
259 elif userChoice == 5:
260 exiting()
261 else:
262 validOption()
263
264
14 | P a g e
265 # Function to display the add book menu and handle user choices
266 def addBookMenu():
267 # Add book menu options
268 print("1. Home")
269 print("2. Back")
270 print("3. Exit")
271 userChoice = int(input("Enter your Choice to Continue : "))
272 print(" ")
273
274 # User choices handling
275 if userChoice == 1:
276 home()
277 elif userChoice == 2:
278 modifyBook()
279 elif userChoice == 3:
280 exiting()
281 else:
282 validOption()
283
284
285 # Function to add a new book to the library
286 def addBook():
287 print(" ")
288 print("Add Book")
289 print(" ")
290 # Get user input for book details
291 bookId = int(input("Enter the Book ID : "))
292 bookName = input("Enter the Book Name : ")
293 publicationYear = int(input("Enter the Book Publication Year : "))
294 author = input("Enter the Book Author Name : ")
295 print(" ")
296
297 c.execute("SELECT bookId FROM books")
298 result = c.fetchall()
299 db.commit()
300
301 if (bookId,) in result:
302 print(
303 f'The book of book id "{bookId}" is already available in the
304 digital library.'
305 )
306 print(" ")
307 addBookMenu()
308 else:
309 # Execute SQL query to insert the new book into the database
310 c.execute(
311 "INSERT INTO books (bookId, bookName, publicationYear, author)
312 VALUES (%s, %s, %s, %s)",
313 (bookId, bookName, publicationYear, author),
314 )
315 db.commit()
316
317 # Notify the user that the book has been added successfully
318 print("Book added Successfully!")
319 print(" ")
320 addBookMenu()
321
322
323 # Function to display the delete book menu and handle user choices
324 def deleteBookMenu():
325 # Delete book menu options
326 print("1. Home")
327 print("2. Back")
328 print("3. Exit")
329 userChoice = int(input("Enter your Choice to Continue : "))
330 print(" ")
15 | P a g e
331
332 # User choices handling
333 if userChoice == 1:
334 home()
335 elif userChoice == 2:
336 admin()
337 elif userChoice == 3:
338 exiting()
339 else:
340 validOption()
341
342
343 # Function to delete a book from the library
344 def deleteBook():
345 print(" ")
346 print("Delete Book")
347 print(" ")
348 # Get user input for the book ID to be deleted
349 bookId = int(input("Enter the Book ID : "))
350 choice = input("Are you sure to delete the Book? (Yes/No) : ")
351 print(" ")
352
353 c.execute("SELECT bookId FROM books")
354 result = c.fetchall()
355 db.commit()
356
357 if choice.lower() in ["yes", "y"]:
358 if (bookId,) in result:
359 # Execute SQL query to delete the book from the database
360 c.execute("DELETE FROM books WHERE bookId=%s", (bookId,))
361 db.commit()
362
363 # Notify the user that the book has been deleted successfully
364 print("Book deleted Successfully!")
365 print("--------------------------")
366 deleteBookMenu()
367 else:
368 print(
369 f'The book of book id "{bookId}" does not available in the
370 digital library.'
371 )
372 print("--------------------------")
373 deleteBookMenu()
374 elif choice.lower() in ["no", "n"]:
375 print(" ")
376 print("Book Not Deleted!")
377 print("--------------------------")
378 deleteBookMenu()
379 else:
380 validOption()
381
382
383 # Update book menu options
384 def updateBookMenu():
385 print("1. Home")
386 print("2. Back")
387 print("3. Exit")
388 userChoice = int(input("Enter your Choice to Continue : "))
389 print(" ")
390
391 # User choices handling
392 if userChoice == 1:
393 home()
394 elif userChoice == 2:
395 updateUser()
396 elif userChoice == 3:
16 | P a g e
397 exiting()
398 else:
399 validOption()
400
401
402 def notBook(bookId):
403 print(f'The book of book id "{bookId}" does not available in the
404 digital library.')
405 print(" ")
406 updateBookMenu()
407
408
409 # Function to update book details
410 def updateBook():
411 print(" ")
412 print("Update Book Details")
413 print(" ")
414 print("1. Update the Book ID")
415 print("2. Update the Book Name")
416 print("3. Update the Book Publication Year")
417 print("4. Update the Book Author Name")
418 print("5. Home")
419 print("6. Back")
420 print("7. Exit")
421 userChoice = int(input("Enter your Choice to Continue : "))
422 print(" ")
423
424 c.execute("SELECT bookId FROM books")
425 result = c.fetchall()
426 db.commit()
427
428 # User choices handling
429 if userChoice == 1:
430 currentBookId = int(input("Enter the Current Book ID : "))
431 newBookId = int(input("Enter the New Book ID : "))
432
433 if (currentBookId,) in result:
434 # Execute SQL query to update the Book ID
435 c.execute(
436 "UPDATE books SET bookId=%s WHERE bookId=%s", (newBookId,
437 currentBookId)
438 )
439 db.commit()
440
441 print("Book ID changed Successfully!")
442 print("--------------------------")
443 updateBookMenu()
444 else:
445 notBook(currentBookId)
446
447 elif userChoice == 2:
448 bookId = int(input("Enter the Book ID : "))
449 newBookName = input("Enter the New Book Name : ")
450
451 if (bookId,) in result:
452 # Execute SQL query to update the Book Name
453 c.execute(
454 "UPDATE books SET bookName=%s WHERE bookId=%s",
455 (newBookName, bookId)
456 )
457 db.commit()
458
459 print("Book Name changed Successfully!")
460 print("--------------------------")
461 updateBookMenu()
462 else:
17 | P a g e
463 notBook(bookId)
464
465 elif userChoice == 3:
466 bookId = int(input("Enter the Current Book ID : "))
467 newPublicationYear = input("Enter the New Publication Year : ")
468
469 if (bookId,) in result:
470 # Execute SQL query to update the Publication Year
471 c.execute(
472 "UPDATE books SET publicationYear=%s WHERE bookId=%s",
473 (newPublicationYear, bookId),
474 )
475 db.commit()
476
477 print("Book Publication Year changed Successfully!")
478 print("--------------------------")
479 updateBookMenu()
480
481 elif userChoice == 4:
482 bookId = int(input("Enter the Current Book ID : "))
483 newAuthor = input("Enter the New Author Name : ")
484
485 if (bookId,) in result:
486 # Execute SQL query to update the Author Name
487 c.execute(
488 "UPDATE books SET author=%s WHERE bookId=%s",
489 (newAuthor, bookId),
490 )
491 db.commit()
492
493 print("Book Author Name changed Successfully!")
494 print("--------------------------")
495 updateBookMenu()
496 else:
497 notBook(bookId)
498
499 elif userChoice == 5:
500 home()
501 elif userChoice == 6:
502 modifyBook()
503 elif userChoice == 7:
504 exiting()
505 else:
506 validOption()
507
508
509 # Function to display the issue book menu and handle user choices
510 def issueBookMenu():
511 print("1. Home")
512 print("2. Back")
513 print("3. Exit")
514 userChoice = int(input("Enter your Choice to Continue : "))
515 print(" ")
516
517 # User choices handling
518 if userChoice == 1:
519 home()
520 elif userChoice == 2:
521 admin()
522 elif userChoice == 3:
523 exiting()
524 else:
525 validOption()
526
527
528 # Function to issue a book
18 | P a g e
529 def issueBook():
530 print(" ")
531 print("Issue Book")
532 print(" ")
533 bookId = int(input("Enter the Book ID to be Issued: "))
534 userId = int(input("Enter the User ID to whom Book will be Issued: "))
535
536 # Execute SQL query to check the issue status of the book
537 c.execute("SELECT userId FROM users")
538 result1 = c.fetchall()
539 c.execute("SELECT bookId FROM books")
540 result2 = c.fetchall()
541 c.execute("SELECT issueStatus FROM books WHERE bookId=%s", (bookId,))
542 result3 = c.fetchall()
543 db.commit()
544
545 if (userId,) in result1:
546 if (bookId,) in result2:
547 # Check if the book is not already issued
548 if result3[0][0] == "not issued":
549 # Execute SQL queries to update book details and mark it as
550 issued
551 c.execute(
552 "UPDATE books SET issueDate = CURRENT_DATE WHERE bookId
553 = %s",
554 (bookId,),
555 )
556 c.execute(
557 "UPDATE books SET issueTime = CURRENT_TIME WHERE bookId
558 = %s",
559 (bookId,),
560 )
561 c.execute(
562 "UPDATE books SET issueStatus = 'issued' WHERE bookId =
563 %s",
564 (bookId,),
565 )
566 c.execute(
567 "UPDATE books SET returnDate = NULL WHERE bookId = %s",
568 (bookId,)
569 )
570 c.execute(
571 "UPDATE books SET returnTime = NULL WHERE bookId = %s",
572 (bookId,)
573 )
574 c.execute(
575 "UPDATE books SET issuedUserId = %s WHERE bookId = %s",
576 (userId, bookId),
577 )
578 db.commit()
579 c.execute(
580 "select issuedUserId,bookName,issueDate,issueTime from
581 books where bookId=%s",
582 (bookId,),
583 )
584 result = c.fetchall()
585 c.execute(
586 "INSERT INTO issuedBooksDetails (userId,
587 bookId,bookName,issueDate,issueTime) VALUES (%s, %s, %s, %s, %s)",
588 (result[0][0], bookId, result[0][1], result[0][2],
589 result[0][3]),
590 )
591 db.commit()
592
593 print("--------------------------")
594 print(
19 | P a g e
595 f'Book of Book Id "{bookId}" is issued successfully to
596 the User of User Id "{userId}".'
597 )
598 print("--------------------------")
599 returnPolicy()
600 issueBookMenu()
601 else:
602 # Notify the user that the book is already issued
603 print(
604 f'The book of book id "{bookId}" is already issued by
605 another user.'
606 )
607 print("--------------------------")
608 issueBookMenu()
609 else:
610 print(
611 f"Book with book id {bookId} does not available in the
612 digital library."
613 )
614 print("--------------------------")
615 issueBookMenu()
616 else:
617 print(f"User with user id {userId} does not exists in the digital
618 library.")
619 print(" ")
620 issueBookMenu()
621
622
623 # Function to display the return book menu and handle user choices
624 def returnBookMenu():
625 print("1. Home")
626 print("2. Back")
627 print("3. Exit")
628 userChoice = int(input("Enter your Choice to Continue : "))
629 print(" ")
630
631 # User choices handling
632 if userChoice == 1:
633 home()
634 elif userChoice == 2:
635 admin()
636 elif userChoice == 3:
637 exiting()
638 else:
639 validOption()
640
641
642 # Function to return a book
643 def returnBook():
644 print(" ")
645 print("Return Book")
646 print(" ")
647 bookId = int(input("Enter the Book ID to be Returned: "))
648
649 # Execute SQL query to check the issue status of the book
650 c.execute("SELECT bookId FROM books")
651 result1 = c.fetchall()
652 c.execute("SELECT issueStatus FROM books WHERE bookId=%s", (bookId,))
653 result2 = c.fetchall()
654
655 db.commit()
656
657 if (bookId,) in result1:
658 # Check if the book is issued
659 if result2[0][0] == "issued":
660 # Execute SQL queries to update book details and mark it as
20 | P a g e
661 returned
662 c.execute(
663 "UPDATE books SET returnDate = CURRENT_DATE WHERE bookId =
664 %s",
665 (bookId,),
666 )
667 c.execute(
668 "UPDATE books SET returnTime = CURRENT_TIME WHERE bookId =
669 %s",
670 (bookId,),
671 )
672 c.execute(
673 "UPDATE books SET issueStatus = 'not issued' WHERE bookId =
674 %s",
675 (bookId,),
676 )
677 db.commit()
678 c.execute(
679 "select issuedUserId,returnDate,returnTime from books where
680 bookId=%s",
681 (bookId,),
682 )
683 result = c.fetchall()
684
685 c.execute(
686 "UPDATE issuedBooksDetails SET returnDate = %s, returnTime
687 = %s WHERE userId = %s AND bookId = %s",
688 (result[0][1], result[0][2], result[0][0], bookId),
689 )
690
691 db.commit()
692 c.execute(
693 "UPDATE books SET issuedUserId = NULL WHERE bookId = %s",
694 (bookId,)
695 )
696 db.commit()
697
698 print(f'The book of book id "{bookId}" is returned
699 successfully.')
700
701 c.execute("select issueDate from books WHERE bookId = %s",
702 (bookId,))
703 issueDate = c.fetchall()
704 c.execute("select returnDate from books WHERE bookId = %s",
705 (bookId,))
706 returnDate = c.fetchall()
707 db.commit()
708
709 c.execute("UPDATE books SET issueDate = NULL WHERE bookId =
710 %s", (bookId,))
711 c.execute("UPDATE books SET issueTime = NULL WHERE bookId =
712 %s", (bookId,))
713 c.execute("UPDATE books SET returnDate = NULL WHERE bookId =
714 %s", (bookId,))
715 c.execute("UPDATE books SET returnTime = NULL WHERE bookId =
716 %s", (bookId,))
717 db.commit()
718
719 d1 = datetime.strptime(f"{issueDate[0][0]}", "%Y-%m-%d")
720 d2 = datetime.strptime(f"{returnDate[0][0]}", "%Y-%m-%d")
721 dateDifference = d1 - d2
722
723 if dateDifference.days > 14:
724 extraDays = dateDifference.days - 14
725 fine = extraDays * 5
726 print("Fine(in Rs.) : ", fine)
c.execute(
21 | P a g e
727 "update issuedBooksDetails set fineInRs=%s where
728 userId=%s and bookId=%s",
729 (fine, result[0][0], bookId),
730 )
731 db.commit()
732 else:
733 fine = 0 * 5
734 print("Fine(in Rs.) : ", fine)
735 c.execute(
736 "update issuedBooksDetails set fineInRs=%s where
737 userId=%s and bookId=%s",
738 (fine, result[0][0], bookId),
739 )
740 db.commit()
741
742 print("--------------------------")
743 returnBookMenu()
744 else:
745 # Notify the user that the book is not issued
746 print(f'The book of book id "{bookId}" is not issued by any
747 user.')
748 print("--------------------------")
749 returnBookMenu()
750 else:
751 print(f"Book with book id {bookId} does not available in the
752 digital library.")
753 print(" ")
754 returnBookMenu()
755
756
757 # Function to display the add user menu and handle user choices
758 def addUserMenu():
759 # Add user menu options
760 print("1. Home")
761 print("2. Back")
762 print("3. Exit")
763 userChoice = int(input("Enter your Choice to Continue : "))
764 print(" ")
765
766 # User choices handling
767 if userChoice == 1:
768 home()
769 elif userChoice == 2:
770 modifyUser()
771 elif userChoice == 3:
772 exiting()
773 else:
774 validOption()
775
776
777 # Function to add a new user
778 def addUser():
779 print(" ")
780 print("Add User")
781 print(" ")
782 # Get user input for user details
783 userId = int(input("Enter the User ID : "))
784 userName = input("Enter the User Name : ")
785 userPhoneNumber = input("Enter the User Phone Number : ")
786 userEmailId = input("Enter the User Email ID : ")
787 password = input("Enter the User Password : ")
788 print(" ")
789
790 c.execute("SELECT userId FROM users")
791 result = c.fetchall()
792 db.commit()
22 | P a g e
793
794 if (userId,) in result:
795 print(
796 f'The user of user number "{userId}" is already enrolled in the
797 digital library.'
798 )
799 print(" ")
800 addUserMenu()
801 else:
802 # Execute SQL query to insert the new user into the database
803 c.execute(
804 "INSERT INTO users (userId, userName, phoneNumber, emailId,
805 password) VALUES (%s, %s, %s, %s, %s)",
806 (userId, userName, userPhoneNumber, userEmailId, password),
807 )
808 db.commit()
809
810 # Notify the user that the user has been added successfully
811 print(" ")
812 print("User added successfully!")
813 print(" ")
814 addUserMenu()
815
816
817 # Function to display the delete user menu and handle user choices
818 def deleteUserMenu():
819 # Delete user menu options
820 print("1. Home")
821 print("2. Back")
822 print("3. Exit")
823 userChoice = int(input("Enter your Choice to Continue : "))
824 print(" ")
825
826 # User choices handling
827 if userChoice == 1:
828 home()
829 elif userChoice == 2:
830 modifyUser()
831 elif userChoice == 3:
832 exiting()
833 else:
834 validOption()
835
836
837 # Function to delete a user
838 def deleteUser():
839 print(" ")
840 print("Delete User")
841 print(" ")
842 # Get user input for the user ID to be deleted
843 userId = int(input("Enter the User ID : "))
844 choice = input("Are you sure to delete the User? (Yes/No) : ")
845
846 c.execute("SELECT userId FROM users")
847 result = c.fetchall()
848 db.commit()
849
850 if choice.lower() in ["yes", "y"]:
851 if (userId,) in result:
852 c.execute("DELETE FROM users WHERE userId=%s", (userId,))
853 db.commit()
854
855 # Notify the user that the user has been deleted successfully
856 print("User deleted successfully!")
857 print("--------------------------")
858 deleteUserMenu()
23 | P a g e
859 else:
860 print(
861 f'The user of user id "{userId}" does not enrolled in the
862 digital library.'
863 )
864 print("--------------------------")
865 deleteUserMenu()
866 elif choice.lower() in ["no", "n"]:
867 print(" ")
868 print("User Not Deleted!")
869 print("--------------------------")
870 deleteUserMenu()
871 else:
872 validOption()
873
874
875 # Function to display the update user menu and handle user choices
876 def updateUserMenu():
877 print("1. Home")
878 print("2. Back")
879 print("3. Exit")
880 userChoice = int(input("Enter your Choice to Continue : "))
881
882 # User choices handling
883 if userChoice == 1:
884 home()
885 elif userChoice == 2:
886 updateUser()
887 elif userChoice == 3:
888 exiting()
889 else:
890 validOption()
891
892
893 def notUser(userId):
894 print(f'The user of user id "{userId}" does not enrolled in the digital
895 library.')
896 print(" ")
897 updateBookMenu()
898
899
900 # Function to update user details
901 def updateUser():
902 print(" ")
903 print("Update User Details")
904 print(" ")
905 # Display user update options
906 print("1. Update the User ID")
907 print("2. Update the User Name")
908 print("3. Update the User Phone Number")
909 print("4. Update the User Email ID")
910 print("5. Update the User Password")
911 print("6. Home")
912 print("7. Back")
913 print("8. Exit")
914 # Get user choice
915 userChoice = int(input("Enter your Choice to Continue : "))
916 print(" ")
917
918 c.execute("SELECT userId FROM users")
919 result = c.fetchall()
920 db.commit()
921
922 if userChoice == 1:
923 # Update user ID
924 currentUserId = int(input("Enter the Current User ID : "))
24 | P a g e
925 newUserId = int(input("Enter the New User ID : "))
926
927 if (currentUserId,) in result:
928 c.execute(
929 "update users set userId=%s where userId=%s", (newUserId,
930 currentUserId)
931 )
932 db.commit()
933
934 print("User ID changed Successfully!")
935 print("--------------------------")
936 updateUserMenu()
937 else:
938 notUser(currentUserId)
939
940 elif userChoice == 2:
941 # Update user name
942 userId = int(input("Enter the User ID : "))
943 newUserName = input("Enter the New User Name : ")
944
945 if (userId,) in result:
946 c.execute(
947 "update users set userName=%s where userId=%s",
948 (newUserName, userId)
949 )
950 db.commit()
951
952 print("User Name changed Successfully!")
953 print("--------------------------")
954 updateUserMenu()
955 else:
956 notUser(userId)
957
958 elif userChoice == 3:
959 # Update user phone number
960 userId = int(input("Enter the Current User ID : "))
961 newPhoneNumber = input("Enter the New Phone Number : ")
962
963 if (userId,) in result:
964 c.execute(
965 "update users set phoneNumber=%s where userId=%s",
966 (newPhoneNumber, userId),
967 )
968 db.commit()
969
970 print("User Phone Number changed Successfully!")
971 print("--------------------------")
972 updateUserMenu()
973 else:
974 notUser(userId)
975
976 elif userChoice == 4:
977 # Update user email ID
978 userId = int(input("Enter the Current User ID : "))
979 newEmailId = input("Enter the New Email ID : ")
980
981 if (userId,) in result:
982 c.execute(
983 "update users set emailId=%s where userId=%s", (newEmailId,
984 userId)
985 )
986 db.commit()
987
988 print("User Email ID changed Successfully!")
989 print("--------------------------")
990 updateUserMenu()
25 | P a g e
991 else:
992 notUser(userId)
993
994 elif userChoice == 5:
995 # Update user password
996 userId = int(input("Enter the Current User ID : "))
997 newPassword = input("Enter the New Password : ")
998 if (userId,) in result:
999 c.execute(
1000 "update users set password=%s where userId=%s",
1001 (newPassword, userId)
1002 )
1003 db.commit()
1004
1005 print("User Password changed Successfully!")
1006 print("--------------------------")
1007 updateUserMenu()
1008 else:
1009 notUser(userId)
1010
1011 elif userChoice == 6:
1012 # Return to home
1013 home()
1014 elif userChoice == 7:
1015 # Go back to the previous menu
1016 modifyUser()
1017 elif userChoice == 8:
1018 # Exit the program
1019 exiting()
1020 else:
1021 validOption()
1022
1023
1024 # Function to modify user
1025 def modifyUser():
1026 print(" ")
1027 print("Modify User")
1028 print(" ")
1029 # Display user modification options
1030 print("1. Add User")
1031 print("2. Delete User")
1032 print("3. Update User Details")
1033 print("4. Home")
1034 print("5. Back")
1035 print("6. Exit")
1036 # Get user choice
1037 userChoice = int(input("Enter your Choice to Continue : "))
1038 print(" ")
1039
1040 # User choices handling
1041 if userChoice == 1:
1042 # Add a new user
1043 addUser()
1044 elif userChoice == 2:
1045 # Delete a user
1046 deleteUser()
1047 elif userChoice == 3:
1048 # Update user details
1049 updateUser()
1050 elif userChoice == 4:
1051 # Return to home
1052 home()
1053 elif userChoice == 5:
1054 # Return to the previous menu
1055 admin()
1056 elif userChoice == 6:
26 | P a g e
1057 # Exit the program
1058 exiting()
1059 else:
1060 validOption()
1061
1062
1063 # Display users menu options
1064 def displayUsersMenu():
1065 print("1. Home")
1066 print("2. Back")
1067 print("3. Exit")
1068 userChoice = int(input("Enter your Choice to Continue : "))
1069
1070 # User choices handling
1071 if userChoice == 1:
1072 home()
1073 elif userChoice == 2:
1074 admin()
1075 elif userChoice == 3:
1076 exiting()
1077 else:
1078 validOption()
1079
1080
1081 # Function to display all users
1082 def displayUsers():
1083 print(" ")
1084 print("Display Users")
1085 print("--------------------------")
1086 # Fetch all users from the database
1087 c.execute("SELECT * FROM users ORDER BY userId")
1088 result = c.fetchall()
1089 db.commit()
1090
1091 if result:
1092 # Display user information
1093 print("Users enrolled in the Digital Library are :")
1094 i = 0
1095 for row in result:
1096 i += 1
1097 r = length(i)
1098 print(f"{i}. User ID : {row[0]}")
1099 print(" " * r + f"User Name : {row[1]}")
1100 print(" " * r + f"Phone Number : {row[2]}")
1101 print(" " * r + f"Email ID : {row[3]}")
1102 print(" " * r + f"Admin Status : {row[5]}")
1103 print("--------------------------")
1104 displayUsersMenu()
1105
1106 else:
1107 print("No users found.")
1108 print("--------------------------")
1109 displayUsersMenu()
1110
1111
1112 # Search user menu options
1113 def searchUsersMenu():
1114 print("1. Home")
1115 print("2. Back")
1116 print("3. Exit")
1117 userChoice = int(input("Enter your Choice to Continue : "))
1118
1119 # User choices handling
1120 if userChoice == 1:
1121 home()
1122 elif userChoice == 2:
27 | P a g e
1123 searchUsers()
1124 elif userChoice == 3:
1125 exiting()
1126 else:
1127 validOption()
1128
1129
1130 # Function to search users by ID
1131 def searchUsersbyId():
1132 print("--------------------------")
1133 print("Search Users by User ID")
1134 print(" ")
1135 # Get user ID to search
1136 userId = int(input("Enter the User ID to search the User : "))
1137
1138 # Search for the user in the database
1139 c.execute("SELECT * FROM users WHERE userId=%s", (userId,))
1140 result = c.fetchall()
1141 db.commit()
1142
1143 if result:
1144 # Display user information if found
1145 print(f'User enrolled in the Digital Library with the User ID
1146 "{userId}" is :')
1147 i = 0
1148 for row in result:
1149 i += 1
1150 r = length(i)
1151 print(f"{i}. User ID : {row[0]}")
1152 print(" " * r + f"User Name : {row[1]}")
1153 print(" " * r + f"Phone Number : {row[2]}")
1154 print(" " * r + f"Email ID : {row[3]}")
1155 print(" " * r + f"Admin Status : {row[5]}")
1156 print("--------------------------")
1157 searchUsersMenu()
1158
1159 else:
1160 # Handle case when no user is found
1161 print(f'No user found with the user id "{userId}".')
1162 print(" ")
1163 searchUsersMenu()
1164
1165
1166 # Function to search users by keyword
1167 def searchUsersbyKeyword():
1168 print(" ")
1169 print("Search Users by Keyword")
1170 print(" ")
1171 # Get keyword input from the user
1172 keyword = input("Enter a Keyword to search Users : ")
1173
1174 # Search for users with the given keyword in their names
1175 c.execute(
1176 "SELECT * FROM users WHERE userName LIKE '%{}%' ORDER BY
1177 userId".format(keyword)
1178 )
1179 result = c.fetchall()
1180 db.commit()
1181
1182 if result:
1183 # Display user information if users are found
1184 print(
1185 f'Users enrolled in the Digital Library with the Keyword
1186 "{keyword}" are :'
1187 )
1188 i = 0
28 | P a g e
1189 for row in result:
1190 i += 1
1191 r = length(i)
1192 print(f"{i}. User ID : {row[0]}")
1193 print(" " * r + f"User Name : {row[1]}")
1194 print(" " * r + f"Phone Number : {row[2]}")
1195 print(" " * r + f"Email ID : {row[3]}")
1196 print(" " * r + f"Admin Status : {row[5]}")
1197 print("--------------------------")
1198 searchUsersMenu()
1199
1200 else:
1201 # Handle case when no user is found
1202 print(f'No users found with the keyword "{keyword}".')
1203 print(" ")
1204 searchUsersMenu()
1205
1206
1207 # Function to search users
1208 def searchUsers():
1209 print(" ")
1210 print("Search Users")
1211 print(" ")
1212 # User search menu
1213 print("1. Search by User ID")
1214 print("2. Search by Keyword")
1215 print("3. Home")
1216 print("4. Back")
1217 print("5. Exit")
1218 userChoice = int(input("Enter your Choice to Continue : "))
1219 print(" ")
1220
1221 # User choices handling
1222 if userChoice == 1:
1223 searchUsersbyId()
1224 elif userChoice == 2:
1225 searchUsersbyKeyword()
1226 elif userChoice == 3:
1227 home()
1228 elif userChoice == 4:
1229 admin()
1230 elif userChoice == 5:
1231 exiting()
1232 else:
1233 validOption()
1234
1235
1236 # Function to modify books
1237 def modifyBook():
1238 print(" ")
1239 print("Modify Book")
1240 print(" ")
1241 # Book modification menu
1242 print("1. Add Book")
1243 print("2. Delete Book")
1244 print("3. Update Book Details")
1245 print("4. Home")
1246 print("5. Back")
1247 print("6. Exit")
1248 userChoice = int(input("Enter your Choice to Continue : "))
1249 print(" ")
1250
1251 # User choices handling
1252 if userChoice == 1:
1253 addBook()
1254 elif userChoice == 2:
29 | P a g e
1255 deleteBook()
1256 elif userChoice == 3:
1257 updateBook()
1258 elif userChoice == 4:
1259 home()
1260 elif userChoice == 5:
1261 admin()
1262 elif userChoice == 6:
1263 exiting()
1264 else:
1265 validOption()
1266
1267
1268 # Function to manage notes
1269 def notes():
1270 print(" ")
1271 print("Notes")
1272 print(" ")
1273 # Display menu options
1274 print("1. Modify Note")
1275 print("2. Display Notes")
1276 print("3. Search Notes")
1277 print("4. Home")
1278 print("5. Back")
1279 print("6. Exit")
1280 # Get user choice
1281 userChoice = int(input("Enter your Choice to Continue : "))
1282 print(" ")
1283
1284 # Handle user choices
1285 if userChoice == 1:
1286 modifyNote()
1287 elif userChoice == 2:
1288 displayNotes()
1289 elif userChoice == 3:
1290 searchNotes()
1291 elif userChoice == 4:
1292 home()
1293 elif userChoice == 5:
1294 user()
1295 elif userChoice == 6:
1296 exiting()
1297 else:
1298 validOption()
1299
1300
1301 # Function to display the add note menu and handle user choices
1302 def addNoteMenu():
1303 print("1. Home")
1304 print("2. Back")
1305 print("3. Exit")
1306 # Get user choice
1307 userChoice = int(input("Enter your Choice to Continue : "))
1308
1309 # Handle user choices
1310 if userChoice == 1:
1311 home()
1312 elif userChoice == 2:
1313 modifyNote()
1314 elif userChoice == 3:
1315 exiting()
1316 else:
1317 validOption()
1318
1319
1320 # Function to add note
30 | P a g e
1321 def addNote():
1322 print(" ")
1323 print("Add Note")
1324 print(" ")
1325 # Get note details from the user
1326 noteNumber = int(input("Enter the Note Number : "))
1327 noteTitle = input("Enter the Note Title : ")
1328 noteDescription = input("Enter the Note Description : ")
1329 print(" ")
1330
1331 c.execute("SELECT noteNumber FROM notes where userId=%s", (USERID,))
1332 result = c.fetchall()
1333 db.commit()
1334
1335 if (noteNumber,) in result:
1336 print(
1337 f'The note of note number "{noteNumber}" is already exists in
1338 the digital library.'
1339 )
1340 print(" ")
1341 addNoteMenu()
1342
1343 else:
1344 # Execute SQL query to insert the note into the database
1345 c.execute(
1346 "INSERT INTO notes (userId, noteNumber, noteTitle,
1347 noteDescription, updateDate, updateTime) VALUES (%s, %s, %s, %s,
1348 CURRENT_DATE, CURRENT_TIME)",
1349 (USERID, noteNumber, noteTitle, noteDescription),
1350 )
1351 db.commit()
1352
1353 print(f'The note of note number "{noteNumber}" is added
1354 successfully.')
1355 print(" ")
1356 addNoteMenu()
1357
1358
1359 # Function to display the delete note menu and handle user choices
1360 def deleteNoteMenu():
1361 # Display menu options after deleting the note
1362 print("1. Home")
1363 print("2. Back")
1364 print("3. Exit")
1365 # Get user choice
1366 userChoice = int(input("Enter your Choice to Continue : "))
1367 print(" ")
1368
1369 # Handle user choices
1370 if userChoice == 1:
1371 home()
1372 elif userChoice == 2:
1373 modifyNote()
1374 elif userChoice == 3:
1375 exiting()
1376 else:
1377 validOption()
1378
1379
1380 # Function to delete a note
1381 def deleteNote():
1382 print(" ")
1383 print("Delete Note")
1384 print(" ")
1385 # Get note number to be deleted from the user
1386 noteNumber = int(input("Enter the Note Number to Delete the Note : "))
31 | P a g e
MySQL
Database
32 | P a g e
Library Database:
Books Table:
Users Table:
33 | P a g e
Notes Table:
34 | P a g e
Outputs
35 | P a g e
Starting of the program:
Admin Authentication:
36 | P a g e
Updating user details:
37 | P a g e
Updating book details:
38 | P a g e
User Authentication:
About Library:
39 | P a g e
News:
Wikipedia Articles:
40 | P a g e
Issued Books Details:
41 | P a g e
Existing the program:
42 | 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-in-
Python/22803
https://gist.github.com/rene-
d/9e584a7dd2935d0f461904b9f2950007
6. Class 11th & 12th Computer Science Arihant Books
43 | P a g e