0% found this document useful (0 votes)
21 views25 pages

Ilovepdf Merged

Uploaded by

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

Ilovepdf Merged

Uploaded by

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

BRGSBV-110032

computer
science
project
on Library management system

SUBMITTED TO SUBMITTED BY
Mr. Ankit Panwar NAME- Daksh Nagpal
(LECTURER C.S) Class-XII
SECTION-B
CLASS Roll no -110039
CBSE Roll no -

Session-2024-25
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 == 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 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
690 db.commit()
691 c.execute(
692 "UPDATE books SET issuedUserId = NULL WHERE bookId = %s",
693 (bookId,)
694 )
695 db.commit()
696
697 print(f'The book of book id "{bookId}" is returned
698 successfully.')
699
700 c.execute("select issueDate from books WHERE bookId = %s",
701 (bookId,))
702 issueDate = c.fetchall()
703 c.execute("select returnDate from books WHERE bookId = %s",
704 (bookId,))
705 returnDate = c.fetchall()
706 db.commit()
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
718 d1 = datetime.strptime(f"{issueDate[0][0]}", "%Y-%m-%d")
719 d2 = datetime.strptime(f"{returnDate[0][0]}", "%Y-%m-%d")
720 dateDifference = d1 - d2
721
722 if dateDifference.days > 14:
723 extraDays = dateDifference.days - 14
724 fine = extraDays * 5
725 print("Fine(in Rs.) : ", fine)
726 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

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