0% found this document useful (0 votes)
19 views

Digital Library .Ppt

Uploaded by

Mr. D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Digital Library .Ppt

Uploaded by

Mr. D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 57

RAMAKRISHNA MISSION (CBSE)

COMPUTER SCIENCE PROJECT


2024-25

PROJECT TOPIC:
LIBRARY MANAGEMENT SYSTEM
Submitted by:
Name: Deependra Singh
Kushwah
Class: XII-B
CBSE Roll Number:
Under the Guidance of:
Mr. Hemant Dixit Sir , PGT (CS)
CERTIFICATE

This is to certify that Deependra Singh Kushwah of class: XII -


B of RAMAKRISHNA MISSION (CBSE) has done his project on
LIBRARY MANAGEMENT SYSTEM (DIGITAL LIBRARY)
under my supervision. He has taken interest and has
shown at most sincerity in completion of this project.
I certify this project up to my expectation & as per
guidelines
issued by CBSE, NEW DELHI.

Internal Examiner External Examiner

Principal

1|Page
ACKNOWLEDGMENT

It is with pleasure that I acknowledge my sincere gratitude


to our teacher, MR. HEMANT DIXIT SIR , PGT (CS) who
taught and undertook the responsibility of teaching the
subject computer science. I have been greatly benefited
from his classes.
I am especially indebted to our Principal SWAMI
SUPRADIPTANANDA MAHARAJ who has always been a
source of encouragement and support and without whose
inspiration this project would not have been a successful I
would like to place on record heartfelt thanks to him.
Finally, I would like to express my sincere appreciation for all
the other students for my batch their friendship & the fine
time that we all shared together.

2|Page
HARDWARES AND SOFTWARES
REQUIRED

HARDWARES
1. Desktop Computer / Laptop
2. Mobile Phone

SOFTWARES
1.Python (Latest Version)
2. MySQL
3. MySQL-Connector-Python,Requests,Wikipedia-API,
Datetime, Pyfiglet Modules

3|Page
TABLE OF CONTENTS

S.No. Topic Page No.


1 Certificate 1
2 Acknowledgement 2
Hardwares and Softwares
3 3
Required
4 Introduction 5
5 Python Source Code 10
6 MySQL Database 45
7 Outputs 48
8 References 56

4|Page
INTRODUCTION
The project LIBRARY MANAGEMENT SYSTEM (DIGITAL
LIBRARY) includes enrolment of users, adding of books into
the library system. The software has the facility to search for
news, Wikipedia articles. It includes an authentication
facility for admin and user to login into the admin panel and
user panel resp. of the system. User can see the books
available, details of books issued by the user in the digital
library. The Library Management System can be login using a
user ID and password. It is accessible either by an admin or
user. Only the admin can add, delete and update the data of
users and books into the database. The data can be retrieved
easily.
The interface is very user-friendly. The data are well
protected for personal use and makes the data
processing very fast.
The purpose of the project entitled as “DIGITAL LIBRARY”
is to computerize the Front Library Management to
develop software which is user friendly, simple, fast, and
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 ==
70 2:
71 home()
72 elif userChoice == 3:
73 user()
74 elif userChoice == 4:
75 exiting()
76 else:
77 validOption()
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 # Retrieve the total number of books and users in the library
85 c.execute("SELECT * FROM books")
86 totalBooks = c.fetchall()
87
88 c.execute("SELECT * FROM users")
89 totalUsers = c.fetchall()
90 db.commit()
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
100 len(totalBooks))
print("Total Number of Users Enrolled in the Library : ",
101
102 len(totalUsers))
print(" ")
103 userMenu()
104
105
106
107 # Function to display the list of books in the library
108 def displayBooks():
print(" ")
109 print("Display Books")
110 print(" ")
111 # Retrieve all books from the database
112 c.execute("SELECT * FROM books ORDER BY bookId")
113 result = c.fetchall()
114 db.commit()
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
125 ID :
126 {row[0]}")
127 print(" " * r + f"Book Name : {row[1]}") print(" "
128 * r + f"Publication Year : {row[2]}") print(" "
129 * r + f"Author Name : {row[7]}")
130 print(" " * r + f"Issue Status : {row[8]}")
131 else: print("--------------------------")
132 userMenu()

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 ==
151 2:
152 home()
153 elif userChoice == 3:
154 searchBooks()
155 elif userChoice == 4:
156 exiting()
157 else:
158 validOption()
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
225 ID :
226 {row[0]}")
227 print(" " * r + f"Book Name : {row[1]}") print(" "
228 * r + f"Publication Year : {row[2]}") print(" "
229 * r + f"Author Name : {row[7]}")
230 searchBooksMenu()
print(" " * r + f"Issue Status : {row[8]}")
231 else: print("--------------------------")
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 )
256 elif userChoice == 3:
257 home()
258 elif userChoice == 4:
259 user()
260 elif userChoice == 5:
261 exiting()
262 else:
263 validOption()
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 ==
336 2:
337 admin()
338 elif userChoice == 3:
339 exiting()
340 else:
341 validOption()
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
360 the book from the database
361 c.execute("DELETE FROM books WHERE bookId=%s", (bookId,))
362 db.commit()
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
422 Continue
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 c.execute(
570 c.execute(
"UPDATE books SET issuedUserId = %s WHERE bookId = %s",
571 "UPDATE books
(userId, SET returnTime = NULL WHERE bookId =
bookId),
%s", )
572 (bookId,)
573
574
575
576
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(
db.commit()
586 "INSERT INTO issuedBooksDetails (userId,
587 bookId,bookName,issueDate,issueTime) VALUES (%s, %s, %s, %s, %s)",
print("--------------------------")
588 (result[0][0], bookId, result[0][1], result[0][2],
print(
589 result[0][3]),
590
591 19 | P a g e
592
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.")
print(" ")
619 issueBookMenu()
620
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 print("
returnBook(): ")
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 c.execute("SELECT bookId FROM books")
650 result1 = c.fetchall()
651 c.execute("SELECT issueStatus FROM
652 books WHERE bookId=%s", (bookId,))
653 result2 = c.fetchall()
654 db.commit()
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

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 c.execute(
685 "UPDATE issuedBooksDetails SET returnDate = %s,
returnTime
686 = %s WHERE userId = %s AND bookId = %s",
687 ) (result[0][1], result[0][2], result[0][0], bookId),
688
689 db.commit()
690 c.execute(
691 "UPDATE
692 books
693 (bookId,) ) SET
694 issuedU
db.commit()
695 serId =
696 NULL
697 WHERE
print(f'The book of book id "{bookId}" is returned
698 successfully.') bookId
699 = %s",
c.execute("select issueDate from books WHERE bookId = %s",
700
701 (bookId,)) issueDate = c.fetchall()
702 c.execute("select returnDate from books WHERE bookId = %s",
703
704 (bookId,)) returnDate = c.fetchall()
705 db.commit()
706
707
708 c.execute("UPDATE books SET issueDate = NULL WHERE bookId =
709 %s", (bookId,))
710 c.execute("UPDATE books SET issueTime = NULL WHERE bookId =
711 %s", (bookId,))
712 c.execute("UPDATE books SET returnDate = NULL WHERE bookId =
713 %s", (bookId,))
714 c.execute("UPDATE books SET returnTime = NULL WHERE bookId =
715 %s", (bookId,))
716 db.commit()
717 d1 = datetime.strptime(f"{issueDate[0][0]}", "%Y-%m-%d")
718 d2 = datetime.strptime(f"{returnDate[0][0]}", "%Y-%m-%d")
719 dateDifference = d1 - d2
720
721 if dateDifference.days > 14:
722 extraDays = dateDifference.days - 14
723 fine = extraDays * 5
724 print("Fine(in Rs.) : ", fine)
725 c.execute(
726

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 db.commit()
(fine, result[0][0], bookId),
739
740 print("--------------------------")
741 returnBookMenu()
742 else:
743 # Notify the user that the book is not issued
744 print(f'The book of book id "{bookId}" is not issued by any
745
746 print("--------------------------")
747 user.') returnBookMenu()
748 else:
749 print(f"Book with book id {bookId} does not available in the
750
751 print(" ")
752 digital returnBookMenu()
library.")
753
754
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 print(" to add a new user
# Function ")
778 def print("Add
addUser(): User")
779 print(" ")
780 # Get user input for user details
781 userId = int(input("Enter the User ID : "))
782 userName = input("Enter the User Name : ")
783 userPhoneNumber = input("Enter the User Phone Number : ")
784 userEmailId = input("Enter the User Email ID : ")
785 password = input("Enter the User Password : ")
786 print(" ")
787
788 c.execute("SELECT userId FROM users")
789 result = c.fetchall()
790 db.commit()
791
792
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 print(" ")
799 addUserMenu()
800 else:
801 # Execute SQL query to insert the new user into the database
802 c.execute(
803 "INSERT INTO users (userId, userName, phoneNumber, emailId,
804
805 password) VALUES (%s,userName,
(userId, %s, %s, %s, %s)",
userPhoneNumber, userEmailId, password),
806 )
807 db.commit()
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
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 print("
deleteUser(): ")
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 c.execute("SELECT userId FROM users")
846 result = c.fetchall()
847 db.commit()
848
849 if choice.lower() in ["yes", "y"]:
850 if (userId,) in result:
851 c.execute("DELETE FROM users
852 WHERE userId=%s",
853 (userId,))
854 db.commit()
# Notify the user that the user has been deleted successfully
855 print("User deleted successfully!")
856 print("--------------------------")
857 deleteUserMenu()
858

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 ==
886 2:
887 updateUser()
888 elif userChoice == 3:
889 exiting()
890 else:
891 validOption()
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
916 print(" to Continue : "))
Choice ")
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
966 phoneNumber=%s
967 ) where userId=
968 db.commit()
%s",
969 (newPhoneNumber
970 , userId),
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
984 userId) emailId=%s
985 ) where userId=
986 %s",
db.commit()
987 (newEmailId,
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
1016 previous menu
1017 modifyUser()
1018 elif userChoice == 8:
1019 # Exit the program
1020 exiting()
1021 else:
1022 validOption()
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
1033 Details")
1034 print("4. Home")
1035 print("5. Back")
1036 print("6. Exit")
1037 # Get user =
userChoice choice
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
1055 previous menu
1056 admin()
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 ==
1074 2:
1075 admin()
1076 elif userChoice == 3:
1077 exiting()
1078 else:
1079 validOption()
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
1099 ID :
1100 {row[0]}")
1101 print(" " * r +
1102 f"User Name :
1103 {row[1]}")
1104 print(" " * r +
1105 f"Phone Number
1106 else: : {row[2]}")
1107 print("
print("No " users
* r + found.")
1108 print("--------------------------")
f"Email ID :
1109 {row[3]}")
displayUsersMenu()
1110 print(" " * r + f"Admin Status : {row[5]}")
1111 print("--------------------------")
1112 # Search user menu options
displayUsersMenu()
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
1193 ID :
1194 {row[0]}")
1195 print(" " * r +
1196 f"User Name :
1197 {row[1]}")
1198 print(" " * r +
1199 f"Phone Number
1200 else: : {row[2]}")
1201 # Handle"case
print(" * r when
+ no user is found
1202 f"Emailusers
print(f'No ID : found with the keyword "{keyword}".')
1203 {row[3]}")
print(" ")
1204 searchUsersMenu()
print(" " * r + f"Admin Status : {row[5]}")
1205 print("--------------------------")
1206 searchUsersMenu()
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 ==
1288 2:
1289 displayNotes()
1290 elif userChoice == 3:
1291 searchNotes()
1292 elif userChoice == 4:
1293 home()
1294 elif userChoice == 5:
1295 user()
1296 elif userChoice == 6:
1297 exiting()
1298 else:
1299 validOption()
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 ==
1313 2:
1314 modifyNote()
1315 elif userChoice == 3:
1316 exiting()
1317 else:
1318 validOption()
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 print(" ")
1340 addNoteMenu()
1341
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 db.commit()
1351
1352
1353 print(f'The note of note number "{noteNumber}" is added
1354 successfully.')
print(" ")
1355 addNoteMenu()
1356
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
print(" to delete a note ")
1381 def print("Delete
deleteNote(): Note")
1382 print(" ")
1383 # Get note number to be deleted from the user
1384 noteNumber = int(input("Enter the Note Number to Delete the Note : "))
1385
1386
31 | P a g e
1387 choice = input("Are you sure to delete the Note? (Yes/No) : ")
1388 print(" ")
1389
1390 c.execute("SELECT noteNumber FROM notes where userId=%s", (USERID,))
1391 result = c.fetchall()
1392 db.commit()
1393
1394 if choice.lower() in ["yes", "y"]:
1395 if (noteNumber,) in result:
1396 # Execute SQL query to delete
1397 the note from the database
1398 c.execute(
1399 "delete FROM notes WHERE
1400 ) userId=%s and
1401 noteNumber=%s",
db.commit()
1402 (USERID, noteNumber),
1403 print(f'The note of note number "{noteNumber}" is deleted
1404 successfully.')
1405 print("--------------------------")
1406 deleteNoteMenu()
1407
1408 else:
1409 print(
1410 f'The note of note number "{noteNumber}" does not exists
in
1411 the digital )library.'
1412 print("--------------------------")
1413 deleteNoteMenu()
1414 elif choice.lower() in ["no", "n"]:
1415 print(" ")
1416 print("Note Not Deleted!")
1417 print(" ")
1418 deleteNoteMenu()
1419 else:
1420 validOption()
1421
1422
1423
1424 # Function to display the update notes menu and handle user choices
1425 def updateNotesMenu():
1426 print("1. Home")
1427 print("2. Back")
1428 print("3. Exit")
1429 # Get user choice
1430 userChoice = int(input("Enter your Choice to Continue : "))
1431 print(" ")
1432
1433 # Handle user choices
1434 if userChoice == 1:
1435 home()
1436 elif userChoice == 2:
1437 updateNotes()
1438 elif userChoice == 3:
1439 exiting()
1440 else:
1441 validOption()
1442
1443
1444 def notNote(noteNumber):
1445 print(
1446 f'The note of note number "{noteNumber}" does not exists in the
1447 digital
) library.'
1448 print(" ")
1449 updateNotesMenu()
1450
1451
1452

32 | P a g e
1453 # Function to update a note
1454 def updateNotes():
1455 print(" ")
1456 print("Update Notes")
1457 print(" ")
1458 # Display update options
1459 print("1. Update the Note Number")
1460 print("2. Update the Note Title")
1461 print("3. Update the Note Description")
1462 print("4. Home")
1463 print("5. Back")
1464 print("6. Exit")
1465 # Get user choice
1466 userChoice = int(input("Enter your
1467 print(" to Continue : "))
Choice ")
1468
1469 c.execute("SELECT noteNumber FROM notes where userId=%s", (USERID,))
1470 result = c.fetchall()
1471 db.commit()
1472
1473 # Handle user choices
1474 if userChoice == 1:
1475 # Update Note Number
1476 currentNoteNumber = int(input("Enter the Current Note Number : "))
1477 newNoteNumber = int(input("Enter the New Note Number : "))
1478
1479 if (currentNoteNumber,) in result:
1480 # Update date and time
1481 c.execute(
1482 "update notes set updateDate=CURRENT_DATE where userId=
%s
1483 and noteNumber=%s",
1484 ) (USERID, currentNoteNumber),
1485
1486 c.execute(
1487 "update notes set updateTime=CURRENT_TIME where userId=
%s
1488 and noteNumber=%s",
)
1489 (USERID, currentNoteNumber),
1490
1491 # Update Note Number
1492 c.execute(
1493 "update notes set noteNumber=%s where userId=%s and
1494 noteNumber=%s",
)
1495 (newNoteNumber, USERID, currentNoteNumber),
db.commit()
1496
1497 print("Note Number changed Successfully!")
1498 print("--------------------------")
1499 updateNotesMenu()
1500 else:
1501 notNote(currentNoteNumber)
1502
1503 elif userChoice == 2:
1504 # Update Note Title
1505 noteNumber = int(input("Enter the Current Note Number : "))
1506 newTitle = input("Enter the New Note Title : ")
1507
1508
1509
1510 if (noteNumber,) in result:
1511 # Update date and time
1512 c.execute(
1513 "update notes set updateDate=CURRENT_DATE where userId=
%s )
1514 and noteNumber=%s",
c.execute(
1515 (USERID,notes
"update noteNumber),
set updateTime=CURRENT_TIME where userId=%s
1516
1517
1518 33 | P a g e
1519 and noteNumber=%s",
1520 (USERID, noteNumber),
1521 )
1522 # Update Note Title
1523 c.execute(
1524 "update notes set noteTitle=%s where userId=%s and
1525 noteNumber=%s",
1526 (newTitle, USERID, noteNumber),
1527 )
1528 db.commit()
1529
1530 print("Note Title changed Successfully!")
1531 print("--------------------------")
1532 updateNotesMenu()
1533 else:
1534 notNote(noteNumber)
1535
1536 elif userChoice == 3:
1537 # Update Note Description
1538 noteNumber = int(input("Enter the Current Note Number : "))
1539 newDescription = input("Enter the New Note Description : ")
1540
1541 if (noteNumber,) in result:
1542 # Update date and time
1543 c.execute(
1544 "update notes set updateDate=CURRENT_DATE where userId=
%s
1545 and noteNumber=%s",
1546 ) (USERID, noteNumber),
1547
1548 c.execute(
1549 "update notes set updateTime=CURRENT_TIME where userId=
%s
1550 and noteNumber=%s",
)
1551 (USERID, noteNumber),
1552
1553 # Update Note Description
1554 c.execute(
1555 "update notes set noteDescription=%s where userId=%s and
1556 noteNumber=%s",
)
1557 (newDescription, USERID, noteNumber),
db.commit()
1558
1559 print("Note Description changed successfully!")
1560 print("--------------------------")
1561 updateNotesMenu()
1562 else:
1563 notNote(noteNumber)
1564
1565 elif userChoice == 5:
1566 home()
1567 elif userChoice == 6:
1568 modifyNote()
1569 elif userChoice == 7:
1570 exiting()
1571 else:
1572 validOption()
1573
1574
1575
1576
1577 # Function
print(" to handle note modifications
")
1578 def print("Modify
modifyNote(): Notes")
1579 print(" ")
1580 # Display modification options
1581 print("1. Add Note")
1582 print("2. Delete Note")
1583
1584
34 | P a g e
1585 print("3. Update Notes")
1586 print("4. Home")
1587 print("5. Back")
1588 print("6. Exit")
1589 # Get user choice
1590 userChoice = int(input("Enter your Choice to Continue : "))
1591 print(" ")
1592
1593 # Handle user choices
1594 if userChoice == 1:
1595 addNote()
1596 elif userChoice ==
1597 2:
1598 deleteNote()
1599 elif userChoice == 3:
1600 updateNotes()
1601 elif userChoice == 4:
1602 home()
1603 elif userChoice == 5:
1604 admin()
1605 elif userChoice == 6:
1606 exiting()
1607 else:
1608 validOption()
1609
1610 # Function to display the display notes menu and handle user choices
1611 def displayNotesMenu():
1612 print("1. Home")
1613 print("2. Back")
1614 print("3. Exit")
1615 userChoice = int(input("Enter your Choice to Continue : "))
1616 print(" ")
1617
1618 # Handle user choices
1619 if userChoice == 1:
1620 home()
1621 elif userChoice == 2:
1622 user()
1623 elif userChoice == 3:
1624 exiting()
1625 else:
1626 validOption()
1627
1628
1629 # Function to display notes
1630 def displayNotes():
1631 # Fetch all notes from the database
1632 c.execute("SELECT * FROM notes ORDER BY noteNumber")
1633 result = c.fetchall()
1634 db.commit()
1635
1636 # Check if there are notes available
1637 if result:
1638 print(f"Notes available in the Digital Library are :")
1639 i = 0
1640 for row in result:
1641 i += 1
1642 r = length(i)
1643 print(f"{i}. Note
1644 Number :
1645 {row[1]}")
1646 print(" " * r + f"Note Title : {row[2]}") print(" "
1647 * r + f"Note Description : {row[3]}") print(" "
1648 * r + f"Update Date : {row[4]}")
1649 print(" " * r + f"Update Time : {row[5]}")
1650 print("--------------------------")
displayNotesMenu()

35 | P a g e
1651 else:
1652 # If no notes are found
1653 print("No notes found.")
1654 print("--------------------------")
1655 displayNotesMenu()
1656
1657
1658 # Function to display the search notes menu and handle user choices
1659 def searchNotesMenu():
1660 print("1. Home")
1661 print("2. Back")
1662 print("3. Exit")
1663 userChoice = int(input("Enter your Choice to Continue : "))
1664
1665 # Handle user choices
1666 if userChoice == 1:
1667 home()
1668 elif userChoice ==
1669 2:
1670 searchNotes()
1671 elif userChoice == 3:
1672 exiting()
1673 else:
1674 validOption()
1675
1676 # Function to search notes by note number
1677 def searchNotesbynoteNumber():
1678 # Get the note number to search
1679 noteNumber = int(input("Enter the Note Number to search the Note : "))
1680
1681 # Execute SQL query to fetch notes with the given note number
1682 c.execute("SELECT * FROM notes WHERE bookId=%s", (noteNumber,))
1683 result = c.fetchall()
1684 db.commit()
1685
1686 # Check if notes are found
1687 if result:
1688 print(
1689 f'Note available in the Digital Library with the Note Number
1690 "{noteNumber}" is :'
1691 )
1692 i = 0
1693 for row in result:
1694 i += 1
1695 r = length(i)
1696 print(f"{i}. Note
1697 Number :
1698 {row[1]}")
1699 print(" " * r +
1700 f"Note Title :
1701 {row[2]}")
1702 else: print(" " * r
1703 # If+nof"Note
notes are found with the given note number
1704 Description
print(f'No :
note found with the note number "{noteNumber}".')
1705 {row[3]}")
print(" ")
1706 print("-------
searchNotesMenu()
1707 --------------
1708 -----")
1709 # Function to search notes by keyword
searchNotesMenu()
1710 def searchNotesbyKeyword():
1711 print(" ")
1712 print("Search Notes by Keyword")
1713 print(" ")
1714 # Get keyword from user
1715 keyword = input("Enter a Keyword to search Notes : ")
1716

36 | P a g e
1717 # Execute SQL query to fetch notes with the given keyword in the
title
1718 c.execute(
1719 "SELECT * FROM notes WHERE noteTitle LIKE '%{}%' ORDER BY
1720 noteNumber".format(
1721 ) keyword
1722 )
1723 result = c.fetchall()
1724 db.commit()
1725
1726
1727 # Check if notes are found
1728 if result:
1729 print(
1730 f'Notes available in the Digital Library with the Keyword
1731 "{keyword}"
) are :'
1732 i = 0
1733 for row in result:
1734 i += 1
1735 r = length(i)
1736 print(f"{i}. Note
1737 Number :
1738 {row[1]}")
1739 print(" " * r +
1740 f"Note Title :
1741 {row[2]}")
1742 else: print(" " * r
1743 # If+no f"Note
notes are found with the given keyword
1744 Description
print(f'No notes:found with the keyword "{keyword}".')
1745 {row[3]}")
print(" ")
1746 print("-------
searchNotesMenu()
1747 --------------
1748 -----")
1749 searchNotesMenu()
1750 # Function to handle note searching
1751 def print("
searchNotes(): ")
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
1762 print("
your Choice to Continue : ")) ")
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
1780 # Function to display the change admin menu and handle user choices
1781 def changeAdminMenu():
1782 print("1. Home")

37 | P a g e
1783 print("2. Back")
1784 print("3. Exit")
1785 userChoice = int(input("Enter your Choice to Continue : "))
1786 print(" ")
1787
1788 # Handle user choices
1789 if userChoice == 1:
1790 home()
1791 elif userChoice == 2:
1792 admin()
1793 elif userChoice == 3:
1794 exiting()
1795 else:
1796 validOption()
1797
1798
1799 # Function to change the admin status
1800 def changeAdmin():
1801 print(" ")
1802 print("Change Admin")
1803 print(" ")
1804 # Get new admin's ID and password from the user
1805 newAdminId = int(input("Enter the New Admin's User ID : "))
1806 newAdminPassword = input("Enter the New Admin's Password : ")
1807 choice = input("Are you sure to change the Admin? (Yes/No) : ")
1808 print(" ")
1809
1810 # Check if the entered user ID exists
1811 c.execute("SELECT password FROM users WHERE userId=%s", (newAdminId,))
1812 result = c.fetchall()
1813 db.commit()
1814
1815 # Check the user's choice to proceed or cancel
1816 if choice.lower() in ["yes", "y"]:
1817 # If the user ID is not valid, print an error message
1818 if len(result) == 0:
1819 print("Please enter a valid user id!")
1820 else:
1821 # If the entered password matches the user's password
1822 if newAdminPassword == result[0][0]:
1823 # Update admin status for all users
1824 c.execute(
1825 "UPDATE users SET adminStatus='not admin' WHERE
1826 adminStatus ='admin'"
1827 )
1828 c.execute(
1829 "UPDATE users SET adminStatus='admin' WHERE
userId
1830 =%s",
1831 ) (newAdminId,),
1832 db.commit()
1833
1834 print("Admin Changed Successfully!")
1835 print("--------------------------")
1836 changeAdminMenu()
1837
1838 else:
1839 print("Please enter a valid password!")
1840 elif choice.lower() in ["no", "n"]:
1841 print("Admin Not Changed!")
1842 print(" ")
1843 changeAdminMenu()
1844 else:
1845 validOption()
1846
1847
1848

38 | P a g e
1849 # Function to authenticate admin
1850 def authAdmin():
1851 print(" ")
1852 print("Admin Authentication")
1853 print(" ")
1854 adminId = int(input("Enter the Admin's User ID : "))
1855 adminPassword = input("Enter the Admin's User Password : ")
1856
1857 # Check if the entered admin ID exists
1858 c.execute("SELECT password FROM users WHERE userId=%s", (adminId,))
1859 result = c.fetchall()
1860 db.commit()
1861
1862 # If the entered admin ID is not valid, print an error message
1863 if len(result) == 0:
1864 print(" ")
1865 print("Please enter a valid user id!")
1866 print("
1867
1868 # If the entered password matches the admin's password
")
1869 if adminPassword == result[0][0]:
else:
1870 global USERID
1871 USERID = adminId
1872 print("\
1873 033[0;35m-------
1874 ----------------
1875 ---\033[0;0m")
1876 print("\033[0;36mAdmin is verified successfully.\033[0;0m")
1877 print("\033[0;35m--------------------------\033[0;0m")
1878 admin() # Call the admin menu
1879 else:
1880 print("Please enter a valid password!")
1881 print("--------------------------")
# Function to display the admin menu
1882 def admin():
1883 print(" ")
1884 print("Admin")
1885 print(" ")
1886 print("1. Login into User Panel")
1887 print("2. Modify User")
1888 print("3. Display Users")
1889 print("4. Search Users")
1890 print("5. Modify Book")
1891 print("6. Issue Book")
1892 print("7. Return Book")
1893 print("8. Change Admin")
1894 print("9. Home")
1895 print("10. Back")
1896 print("11. Exit")
1897 userChoice = int(input("Enter your Choice to Continue : "))
1898 print(" ")
1899
1900 # Handle user choices
1901 if userChoice == 1:
1902 print("You are successfully login into user panel.")
1903 print(" ")
1904
1905 user()
1906 elif userChoice == 2:
1907 modifyUser()
1908 elif userChoice == 3:
1909 displayUsers()
1910 elif userChoice == 4:
1911 searchUsers()
1912 elif userChoice == 5:
1913 modifyBook()
1914 elif userChoice == 6:

39 | P a g e
1915 issueBook()
1916 elif userChoice == 7:
1917 returnBook()
1918 elif userChoice == 8:
1919 changeAdmin()
1920 elif userChoice == 9:
1921 home()
1922 elif userChoice ==
1923 10:
1924 authAdmin()
1925 elif userChoice == 11:
1926 exiting()
1927 else:
1928 validOption()
1929
1930 # Function to authenticate a user
1931 def authUser():
1932 print(" ")
1933 print("User Authentication")
1934 print(" ")
1935 userId = int(input("Enter the User ID : "))
1936 password = input("Enter the User Password : ")
1937
1938 # Check if the entered user ID exists
1939 c.execute("SELECT password FROM users WHERE userId=%s", (userId,))
1940 result = c.fetchall()
1941 db.commit()
1942
1943 # If the entered user ID is not valid, print an error message
1944 if len(result) == 0:
1945 print(" ")
1946 print("Please enter a valid user id!")
1947 print("
1948
1949 # If the entered password matches the user's password
")
1950 if password == result[0][0]:
else:
1951 global USERID
1952 USERID = userId
1953 print("\
1954 033[0;35m------
1955 ---------------
1956 -----\
1957 033[0;0m")
1958 print("\033[0;36mUser is verified successfully.\033[0;0m")
1959 print("\033[0;35m--------------------------\033[0;0m")
1960 user() # Call the user menu
1961 else:
1962 print("Please
# Function to Enter the
search & display a Valid Password!")
wikipedia articles
1963 print("--------------------------")
def wikipediaArticles():
1964 # Function to fetch article details
1965 def fetchingArticle(keyword, articleLength=1500):
1966 # Creating a Wikipedia API object
1967 wiki = wikipediaapi.Wikipedia(language="en", user_agent="digital-
1968 library/1.1")
1969 # Fetching the page for the given search query
1970 page = wiki.page(keyword)
1971
1972 # Checking if the page exists
1973 if not page.exists():
1974 print(
1975 f'Sorry, the Wikipedia Article for the keyword
"{keyword}"
1976 does not exists.'
)
1977 print("--------------------------")
1978 else:
1979 # Displaying article title
1980

40 | P a g e
1981 print("Title : ")
1982 print(page.title)
1983 print("URL : ")
1984 print(page.fullurl)
1985 # Displaying a summary of the article within the specified
1986 length
1987 print("Summary : ")
1988
1989 start = 0
1990 end = 157
1991 article = page.summary[:articleLength]
1992
1993 while end <= articleLength:
1994 print(article[start:end])
1995 start += 157
1996 end += 157
1997 else:
1998 print("--------------------------")
1999
2000 print(" ")
2001 print("Search Articles")
2002 print("--------------------------")
2003 # Taking user input for the keyword and article length
2004 keyword = input("Enter the Keyword for searching the Wikipedia Article
2005 :"
2006 ) articleLength = int(input("Enter the Article Length : "))
2007
print(" ")
2008
2009 # Calling the function to fetch and display the article
2010 fetchingArticle(keyword, articleLength)
2011
2012 userMenu()
2013
2014
2015 # Function to search & display the news
2016 def news():
2017 def fetchNews(apiKey, country="in", category="science", numArticles=5):
2018 url = f"https://newsapi.org/v2/top-headlines"
2019 params = {
2020 "apiKey": apiKey,
2021 "country": country,
2022 "category": category,
2023 "pageSize": numArticles,
2024 }
2025 response = requests.get(url, params=params)
2026
2027 if response.status_code == 200:
2028 news_data = response.json()
2029 articles =
2030 news_data.get("articles",
2031 [])
for i, article in enumerate(articles, start=1):
2032 print(f"{i}. {article['title']}")
2033 print(f" Source:
{article['source']['name']}")
2034 print(f" URL: {article['url']}")
2035 print("--------------------------")
2036
2037 else:
2038 print(f"Error {response.status_code}: {response.text}")
2039 print("--------------------------")
2040
2041 API_KEY = "YOUR_API_KEY"
2042
2043 print(" ")
2044 print("News")
2045 print(" ")
2046 print("Country codes are : ")

41 | P a g e
2047 print("https://newsapi.org/sources")
2048 print("Categories are : ")
2049 print("business, entertainment, general, health, science, sports,
2050 technology")
2051 print(" ")
2052 country = input("Enter the Country Code : ")
2053 category = input("Enter the Category : ")
2054 numArticles = int(input("Enter the Number of
2055 Articles
print(" : ")) ")
2056
2057 fetchNews(API_KEY, country, category, numArticles)
2058
2059 userMenu()
2060
2061
2062 # Function to display the issued books details of a user
2063 def issuedBooksDetails():
2064 print(" ")
2065 print("Issued Books Details")
2066 print(" ")
2067 returnPolicy()
2068
2069 c.execute(
2070 "SELECT * FROM issuedBooksDetails WHERE userId=%s ORDER BY
bookId",
2071 (USERID,)
)
2072 result = c.fetchall()
2073 db.commit()
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
2086 ID : ",
2087 row[1])
2088 print(" " * r +
2089 "Book Name :
2090 ", row[2])
2091 print(" " * r +
2092 "Issue Date :
2093 ", row[3])
2094 print(" " * r +
2095 "Issue Time :
2096 ", row[4])
2097 # Function to display
print(" " * r +the user menu
2098 def print("
user(): "Return Date : ")
2099 ", row[5])
print("User")
2100 print(" " * r +
print(" ")
2101 # Check "Return
if the entered
Time : user ID exists
2102 ", row[6]) userId FROM users WHERE adminStatus="admin"')
c.execute('SELECT
2103 result = c.fetchall()
print(" " * r + "Fine(in Rs.) : ", row[7])
2104 db.commit()
print("--------------------------")
2105 userMenu()
2106 if result[0][0] == USERID:
2107 print("1. Login into Admin
2108 Panel") print("2. About the
2109 Library") print("3. News")
2110 print("4. Wikipedia
2111 Articles") print("5. Display
2112 Books")

42 | P a g e
2113 print("6. Search Books")
2114 print("7. Issued Books Details")
2115 print("8. Notes")
2116 print("9. Home")
2117 print("10. Back")
2118 print("11. Exit")
2119 userChoice = int(input("Enter your Choice to Continue : "))
2120 print(" ")
2121
2122 # Handle user choices
2123 if userChoice == 1:
2124 print("You are successfully login into admin panel.")
2125 print("--------------------------")
2126
2127 admin()
2128 elif userChoice == 2:
2129 aboutLibrary()
2130 elif userChoice == 3:
2131 news()
2132 elif userChoice == 4:
2133 wikipediaArticles()
2134 elif userChoice == 5:
2135 displayBooks()
2136 elif userChoice == 6:
2137 searchBooks()
2138 elif userChoice == 7:
2139 issuedBooksDetails()
2140 elif userChoice == 8:
2141 notes()
2142 elif userChoice == 9:
2143 home()
2144 elif userChoice == 10:
2145 authUser()
2146 elif userChoice == 11:
2147 exiting()
2148 else:
2149 validOption()
2150 else:
2151 print("1. About
2152 Library") print("2.
2153 News")
2154 print("3. Wikipedia
2155 Articles") print("4. Display
2156 Books") print("5. Search
2157 Books")
2158 print("6. Issued Books
2159 Details") print("7. Notes")
2160 print("8. Home")
2161 print("9. Back")
2162 print("10. Exit")
2163 userChoice = int(input("Enter your Choice to Continue : "))
2164 print(" ")
2165
2166 # Handle user choices
2167 if userChoice == 1:
2168 aboutLibrary()
2169 elif userChoice == 2:
2170 news()
2171 elif userChoice == 3:
2172 wikipediaArticles()
2173 elif userChoice == 4:
2174 displayBooks()
2175 elif userChoice == 5:
2176 searchBooks()
2177 elif userChoice == 6:
2178 issuedBooksDetails()
elif userChoice == 7:
notes()
43 | P a g e
2179 elif userChoice == 8:
2180 home()
2181 elif userChoice == 9:
2182 authUser()
2183 elif userChoice == 10:
2184 exiting()
2185 else:
2186 validOption()
2187
2188
2189 # Function to display the main menu
2190 def home():
2191 while True:
2192 print("==========================")
2193 print("\033[1;32m~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0;0m")
2194 print(
2195 "\033[1;31m"
2196 + pyfiglet.figlet_format("Welcome to the", font="banner3",
2197 width=1000)
2198 )
2199 print(
2200 pyfiglet.figlet_format("Digital Library", font="banner3",
2201 width=1000)
2202 + "\033[0;0m"
2203 )
2204 print("\033[1;32m~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0;0m")
2205 print("==========================")
2206 print(" ")
2207 print("Home")
2208 print(" ")
2209 print("1. Admin")
2210 print("2. User")
2211 print("3. Exit")
2212 userChoice = int(input("Enter your Choice to Continue : "))
2213 print(" ")
2214
2215 # Handle user choices
2216 if userChoice == 1:
2217 authAdmin()
2218 elif userChoice ==
2219 2:
2220 authUser()
2221 elif userChoice == 3:
2222 exiting()
2223 else:
2224 validOption()
2225
2226 # Call the main menu function
2227 home()
2228
2229

44 | P a g e
MySQL
Database

45 | P a g e
Library Database:

Books Table:

Users Table:

46 | P a g e
Notes Table:

Issued Books Details Table:

47 | P a g e
Outputs

48 | P a g e
Starting of the program:

Admin Authentication:

Adding a new user:

49 | P a g e
Updating user details:

Adding a new book:

50 | P a g e
Updating book details:

51 | P a g e
User Authentication:

About Library:

52 | P a g e
News:

Wikipedia Articles:

53 | P a g e
Issued Books Details:

54 | P a g e
Existing the program:

55 | P a g e
REFERENCES

1. News API
https://newsapi.org/
2. Wikipedia
https://www.wikipedia.org/
3. Python
https://www.python.org/
4. MySQL
https://www.mysql.com/
5. ANSI Escape Codes in
Python
 https://pypi.org/project/a
nsi/
 https://replit.com/talk/learn/ANSI-Escape-Codes-in-
Python/22803
 https://gist.github.com/rene-
d/9e584a7dd2935d0f461904b9f2950007
6. Class 11th & 12th Computer Science Books

56 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy