0% found this document useful (0 votes)
20 views62 pages

Digital Library

Uploaded by

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

Digital Library

Uploaded by

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

HARDWARES AND SOFTWARES REQUIRED

HARDWARES
1. Desk top Computer/Laptop
2. Mobile Phone

SOFTWARES
1. Python (Latest Version)
2. MySQL
3. My SQL-Connector- Python, Requests, Wikipedia-

API, Date time, Pyfiglet Modules

3|Page
TABLEOFCONTENTS

S.No. Topic PageNo.

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 issyued
by the user in the digital library. The Library Management System can be login
using ID and password. It is accessible either by an admain or user. Only the admin
can add, delete and update the data of users and books into the databases. The data
can 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, 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 location, a virtual space, or both. A 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 organized and maintained by a public body
such as a government, an institution (such as a school or museum), a rporation, 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 organizing
information while interpreting information needs and navigating and analyzing 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 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 paper work 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 user ships can be
done with ease. The automated system saves a considerable amount of time as
opposed to the manual system.

7|Page
FUNCTIONSLIST

 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
 Add Notes
 Delete Notes
 Update Notes
 Display Notes
 Search Notes
 Home
 Back
 Exit

9|Page
10|Page
Sourc Code

1 Import ingnecessary libraries


2 Import mysql.connector#
3 Import pyfiglet
4 Import requests
5 Import wikipediaapi
6 From date time import date time
7
8
9 #Connect to the MySQL data base
10 db= mysql.connector.connect(
11 host="localhost",
12 user="root",
13 password="admin",
14 database="library")
15 c=db. cursor()
16
17
18 #Function todi splay the return policy information
19 def return Policy():
20 print("Return Policy:")
21 print("Theissuedbookshouldbereturnedwithin14days(2weeks).")
22 print("If the user kept the issued book for morethan14days,thenthe
23 user have to pay ₹5 as fine for each extraday the user kept the issued
24 book.")
28 print(" ")
29
30
31 #Functiontocalculatethelengthofagivenintegerafterconvertingit
32 toastring
33 deflength(i):
34 s=str(i)
35 length=len(s)+2
36
37 returnlength
38
39
40 #Functiontodisplayamessageforaninvalidoption
41 defvalidOption():
42 print("Pleaseenteravalidoption!")
43 print(" ")
44
45
46 #Functiontohandleprogramexit
47 defexiting():
48 print("\033[3;34m-------------------------------------------------------\033[0;0m")
49 print("\033[3;33mExitingtheprogram.")
50 print("ThankYou!\033[0;0m")
51 print("\033[3;34m-------------------------------------------------------\033[0;0m")
52 exit()
53
54
55 #Functiontodisplaytheusermenuandhandleuserchoices
56 defuserMenu():
57 #Displayingoptionsfortheuser
58 print("1.AddNote")
59 print("2.Home")
60 print("3.Back")
61 print("4.Exit")
62 #Takinguserchoiceasinput
63 userChoice=int(input("EnteryourChoicetoContinue:"))
64 print(" ")
66 #Handleuserchoices

11|Page
67 if userChoice ==
68 1:addNote()
69 elifuserChoice ==
70 2:home()
71 elifuserChoice ==
72 3:user()
73 elifuserChoice ==
74 4:exiting()
75 else:
76 validOption()
77
78 #Functiontodisplayinformationaboutthelibrary
79 defaboutLibrary():
80 # Retrieve the name of the librarian who is also an
81 adminc.execute("SELECT userName FROM users WHERE
82 adminStatus='admin'")userName= c.fetchall()
83
84 #Retrievethetotalnumberofbooksandusersinthelibrary
85 c.execute("SELECT * FROM
86 books")totalBooks=c.fetchall()
87
c.execute("SELECT * FROM
88 users")totalUsers =
89 c.fetchall()db.commit()
90
91 print(" ")
92 print("AboutLibrary")
93 print(" ")
94 #Displaylibraryinformation
95 print("Year of Library's Establishment : ", 2023)print("Name of
96 the Librarian : ", userName[0]
97 [0])print("TotalNumberofBooksAvailableintheLibrary:",
98 len(totalBooks))
99 print("Total Number of Users Enrolled in the Library :
",len(totalUsers))
100 print(" ")
101 userMenu()
102
103
104 #Functiontodisplaythelistofbooksinthelibrary
105 defdisplayBooks():
106 print(" ")
107 print("DisplayBooks")
108 print(" ")
109 # Retrieve all books from the
110 databasec.execute("SELECT * FROM books ORDER BY
bookId")result= c.fetchall()
111
db.commit()
112
113
#Displaybooksifavailable,otherwisenotifytheuser
114
ifresult:
115 print("Books available in the Digital Library
116 are :")print(" ")
117 i=0
118 for row in
119 result:i+= 1
120 r=length(i)
121 print(f"{i}.BookID:{row[0]}")
122 print(" "* r+ f"BookName :{row[1]}")print(" " * r +
123 f"Publication Year : {row[2]}")print(""
124 *r+f"AuthorName: {row[7]}")
print(" " * r + f"Issue Status :
125 {row[8]}")print("-------------------")
126 userMenu()
127 else:
128
129
130
131
132

12|Page
133
#Notifytheuserifnobooksarefound
134 print("Nobooksfound.")
135 print("-----------------------------")
136 userMenu()
137
138
139 #Searchbooksmenuoptions
140 defsearchBooksMenu():print
141 ("1. Add
142 Note")print("2.Home")
143 print("3.Back")
144 print("4.Exit")
145 userChoice=int(input("EnteryourChoicetoContinue:"))
146
147 #Userchoiceshandling
if userChoice ==
148 1:addNote()
149 elifuserChoice ==
150 2:home()
151 elifuserChoice ==
152 3:searchBooks()
153 elifuserChoice ==
154 4:exiting()
155 else:
156 validOption()
157
158
#FunctiontosearchbooksbyBookID
159
defsearchBooksbyId():
160 print(" ")
161 print("Search Books by Book
162 ID")print(" ")
163 #GetuserinputforBook ID
164 bookId = int(input("Enter the Book ID to search the Book :
165 "))print(" ")
166
167 # Execute SQL query to retrieve book information by Book
168 IDc.execute("SELECT * FROM books WHERE bookId=%s",
(bookId,))result= c.fetchall()
169
db.commit()
170
171
#Displaysearchresultsifbooksarefound,otherwisenotifytheuser
172
ifresult:
173 print(f'Book available in the Digital Library with the Book
174 ID"{bookId}"is :')
175 print(" ")
176 i= 0
177 for row in
178 result:i+= 1
179 r=length(i)
180 print(f"{i}.BookID:{row[0]}")
181 print(" "* r+ f"BookName :{row[1]}")print(" " * r +
f"Publication Year : {row[2]}")print(""
182 *r+f"AuthorName: {row[7]}")
183 print(" " * r + f"Issue Status :
184 {row[8]}")print("-------------------")
185 searchBooksMenu()
186 else:
187 print(f'No book found with the book id
188 "{bookId}".')print(" ")searchBooksMenu()
189
190
191 #Functiontosearchbooksbykeyword
192 defsearchBooksbyKeyword():
193 print(" ")
194
195
196
197
198

13|Page
199 print("Search Books by
200 Keyword")print(" ")
201 #Getuserinputforkeyword
202 keyword = input("Enter a Keyword to search Books :
203 ")print(" ")
204
205 #ExecuteSQLquerytoretrievebooksbykeyword
206 c.execute(
207 "SELECT*FROMbooksWHEREbookNameLIKE'%{}%'ORDERBY
208 bookId".format(keyword)
209 )
210 result =
211 c.fetchall()db.commit()
212 #Displaysearchresultsifbooksarefound,otherwisenotifytheuser
213
ifresult:
214
print(
215 f'Books available in the Digital Library with the
216 Keyword"{keyword}"are :'
217 )
218 print(" ")
219 i= 0
220 for row in
221 result:i+= 1
222 r=length(i)
223 print(f"{i}.BookID:{row[0]}")
print(" "* r+ f"BookName :{row[1]}")print(" " * r +
224 f"Publication Year : {row[2]}")print(""
225 *r+f"AuthorName: {row[7]}")
226 print(" " * r + f"Issue Status :
227 {row[8]}")print("-------------------")
228 searchBooksMenu()
229 else:
230 print(f'No books found with the keyword
231 "{keyword}".')print(" ")
232 searchBooksMenu()
233
234
235 #Functiontodisplaysearchoptionsforbooks
236 defsearchBooks():
print(" ")
237 print("SearchBooks")
238 print(" ")
239 print("1. Search by Book ID")print("2.
240 Search by Keyword")print("3.Home")
241 print("4.Back")
242 print("5.Exit")
243 userChoice = int(input("Enter your Choice to Continue :
244 "))print(" ")
245
246 #Userchoiceshandling
247 if userChoice ==
248 1:searchBooksbyId
249 ()
250 elifuserChoice ==
251 2:searchBooksbyKeyword
252 ()
253 elifuserChoice ==
254 3:home()
255 elifuserChoice ==
256 4:user()
257 elifuserChoice ==
258 5:exiting()
259 else:
260 validOption()
261
262
263
264

14|Page
265 #Functiontodisplaytheaddbookmenuandhandleuserchoices
266 defaddBookMenu():
267 #Addbookmenuoptions
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 #Userchoiceshandling
275 if userChoice ==
276 1:home()
277 elifuserChoice ==
278 2:modifyBook()
279 elifuserChoice ==
280 3:exiting()
281 else:
282 validOption()
283
284
285 #Functiontoaddanewbooktothelibrary
286 defaddBook():
287 print(" ")
288 print("AddBook")
289 print(" ")
290 #Getuserinputforbookdetails
291 bookId = int(input("Enter the Book ID :
292 "))bookName=input("EntertheBookName:")
293 publicationYear = int(input("Enter the Book Publication Year :
294 "))author=input("Enter theBookAuthor Name: ")
295 print(" ")
296
297 c.execute("SELECT bookId FROM
298 books")result= c.fetchall()
299 db.commit()
300
301 if (bookId,) in
302 result:print(
303 f'The book of book id "{bookId}" is already available in
304 thedigitallibrary.'
305 )
306 print(" ")
307 addBookMenu()
308 else:
309 #ExecuteSQLquerytoinsertthenewbookintothedatabase
310 c.execute(
311 "INSERT INTO books (bookId, bookName, publicationYear,
312 author)VALUES(%s, %s, %s, %s)",
313 (bookId,bookName,publicationYear,author),
314 )
315 db.commit()
316
317 #Notifytheuserthatthebookhasbeenaddedsuccessfully
318 print("Book added
319 Successfully!")print(" ")
320 addBookMenu()
321
322
323 #Functiontodisplaythedeletebookmenuandhandleuserchoices
324 defdeleteBookMenu():
325 #Deletebookmenuoptions
326 print("1.Home")
327 print("2.Back")
328 print("3.Exit")
329 userChoice = int(input("Enter your Choice to Continue :
330 "))print(" ")

15|Page
331
332 #Userchoiceshandling
333 if userChoice ==
334 1:home()
335 elifuserChoice ==
336 2:admin()
337 elifuserChoice ==
338 3:exiting()
339 else:
340 validOption()
341
342
343 #Functiontodeleteabookfromthelibrary
344 defdeleteBook():
345 print(" ")
346 print("DeleteBook")
347 print(" ")
348 #GetuserinputforthebookIDtobedeleted
349 bookId=int(input("EntertheBookID:"))
350 choice = input("Are you sure to delete the Book? (Yes/No) :
351 ")print(" ")
352
353 c.execute("SELECT bookId FROM
354 books")result= c.fetchall()
355 db.commit()
356
357 if choice.lower() in ["yes",
358 "y"]:if(bookId,) inresult:
359 # Execute SQL query to delete the book from the
360 databasec.execute("DELETE FROM books WHERE bookId=%s",
361 (bookId,))db.commit()
362
363 #Notifytheuserthatthebookhasbeendeletedsuccessfully
364 print("Book deleted
365 Successfully!")print("-----------")
366 deleteBookMenu()
367 else:
368 print(
369 f'The book of book id "{bookId}" does not available in
370 thedigitallibrary.'
371 )
372 print("--------------------------")
373 deleteBookMenu()
374 elifchoice.lower() in ["no",
375 "n"]:print(" ")
376 print("BookNotDeleted!")
377 print("--------------------------")
378 deleteBookMenu()
379 else:
380 validOption()
381
382
383 #Updatebookmenuoptions
384 defupdateBookMenu():p
385 rint("1.Home")
386 print("2.Back")
387 print("3.Exit")
388 userChoice = int(input("Enter your Choice to Continue :
389 "))print(" ")
390
391 #Userchoiceshandling
392 if userChoice ==
393 1:home()
394 elifuserChoice ==
395 2:updateUser()
396 elifuserChoice==3:

16|Page
397 exiting()
398 else:
399 validOption()
400
401
402 defnotBook(bookId):
403 print(f'The book of book id "{bookId}" does not available in
404 thedigitallibrary.')
405 print(" ")
406 updateBookMenu()
407
408
409 #Functiontoupdatebookdetails
410 defupdateBook():
411 print(" ")
412 print("UpdateBookDetails")print("
413 ")
414 print("1. Update the Book
415 ID")print("2.UpdatetheBookName")
416 print("3. Update the Book Publication
417 Year")print("4. Update the Book Author
418 Name")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
425 books")result= c.fetchall()
426 db.commit()
427
428 #Userchoiceshandling
429 ifuserChoice==1:
430 currentBookId = int(input("Enter the Current Book ID :
431 "))newBookId= int(input("EntertheNewBookID:"))
432
433 if(currentBookId,)inresult:
434 #ExecuteSQLquerytoupdatetheBookID
435 c.execute(
436 "UPDATEbooksSETbookId=%sWHEREbookId=%s",(newBookId,
437 currentBookId)
438 )
439 db.commit()
440
441 print("Book ID changed
442 Successfully!")print("-----------")
443 updateBookMenu()
444 else:
445 notBook(currentBookId)
446
447 elifuserChoice==2:
448 bookId = int(input("Enter the Book ID :
449 "))newBookName=input("EntertheNewBookName:")
450
451 if(bookId,)inresult:
452 #ExecuteSQLquerytoupdatetheBookName
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
460 Successfully!")print("-----------")
461 updateBookMenu()
462 else:

17|Page
463 notBook(bookId)
464
465 elifuserChoice==3:
466 bookId = int(input("Enter the Current Book ID :
467 "))newPublicationYear=input("EntertheNewPublicationYear:")
468
469 if(bookId,)inresult:
470 #ExecuteSQLquerytoupdatethePublicationYear
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
478 Successfully!")print("-----------")
479 updateBookMenu()
480
481 elifuserChoice==4:
482 bookId = int(input("Enter the Current Book ID :
483 "))newAuthor=input("EntertheNewAuthorName:")
484
485 if(bookId,)inresult:
486 #ExecuteSQLquerytoupdatetheAuthorName
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
494 Successfully!")print("-----------")
495 updateBookMenu()
496 else:
497 notBook(bookId)
498
499 elifuserChoice ==
500 5:home()
501 elifuserChoice ==
502 6:modifyBook()
503 elifuserChoice ==
504 7:exiting()
505 else:
506 validOption()
507
508
509 #Functiontodisplaytheissuebookmenuandhandleuserchoices
510 defissueBookMenu():p
511 rint("1.Home")
512 print("2.Back")
513 print("3.Exit")
514 userChoice = int(input("Enter your Choice to Continue :
515 "))print(" ")
516
517 #Userchoiceshandling
518 if userChoice ==
519 1:home()
520 elifuserChoice ==
521 2:admin()
522 elifuserChoice ==
523 3:exiting()
524 else:
525 validOption()
526
527
528 #Functiontoissueabook

18|Page
529 defissueBook():
530 print(" ")
531 print("IssueBook")
532 print(" ")
533 bookId=int(input("EntertheBookIDtobeIssued:"))
534 userId=int(input("EntertheUserIDtowhomBookwillbeIssued:"))
535
536 #ExecuteSQLquerytochecktheissuestatusofthebook
537 c.execute("SELECT userId FROM
538 users")result1 =
539 c.fetchall()c.execute("SELECT bookId
540 FROM books")result2=c.fetchall()
541 c.execute("SELECT issueStatus FROM books WHERE bookId=%s",
542 (bookId,))result3= c.fetchall()
543 db.commit()
544
545 if(userId,)inresult1:
546 if(bookId,)inresult2:
547 #Checkifthebookisnotalreadyissued
548 ifresult3[0][0]=="notissued":
549 #ExecuteSQLqueriestoupdatebookdetailsandmarkitas
550 issued
551 c.execute(
552 "UPDATEbooksSETissueDate=CURRENT_DATEWHEREbookId
553 =%s",
554 (bookId,),
555 )
556 c.execute(
557 "UPDATEbooksSETissueTime=CURRENT_TIMEWHEREbookId
558 =%s",
559 (bookId,),
560 )
561 c.execute(
562 "UPDATEbooksSETissueStatus='issued'WHEREbookId=
563 %s",
564 (bookId,),
565 )
566 c.execute(
567 "UPDATEbooksSETreturnDate=NULLWHEREbookId=%s",
568 (bookId,)
569 )
570 c.execute(
571 "UPDATEbooksSETreturnTime=NULLWHEREbookId=%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
581 frombookswhere bookId=%s",
582 (bookId,),
583 )
584 result =
585 c.fetchall()c.execute
586 (
587 "INSERT INTO issuedBooksDetails
588 (userId,bookId,bookName,issueDate,issueTime)VALUES(%s,%s,%s,%s,%s)",
589 (result[0][0],bookId,result[0][1],result[0][2],
590 result[0][3]),
591 )
592 db.commit()
593
594 print("--------------------------")
print(

19|Page
595 f'Book of Book Id "{bookId}" is issued successfully
596 totheUser of UserId "{userId}".'
597 )
598 print("--------------------------")
599 returnPolicy()i
600 ssueBookMenu()
601 else:
602 #Notifytheuserthatthebookisalreadyissued
603 print(
604 f'Thebookofbookid"{bookId}"isalreadyissuedby
605 anotheruser.'
606 )
607 print("--------------------------")
608 issueBookMenu()
609 else:
610 print(
611 f"Book with book id {bookId} does not available in
612 thedigitallibrary."
613 )
614 print("--------------------------")
615 issueBookMenu()
616 else:
617 print(f"User with user id {userId} does not exists in the
618 digitallibrary.")
619 print(" ")
620 issueBookMenu()
621
622
623 #Functiontodisplaythereturnbookmenuandhandleuserchoices
624 defreturnBookMenu():p
625 rint("1.Home")
626 print("2.Back")
627 print("3.Exit")
628 userChoice = int(input("Enter your Choice to Continue :
629 "))print(" ")
630
631 #Userchoiceshandling
632 if userChoice ==
633 1:home()
634 elifuserChoice ==
635 2:admin()
636 elifuserChoice ==
637 3:exiting()
638 else:
639 validOption()
640
641
642 #Functiontoreturnabook
643 defreturnBook():
644 print(" ")
645 print("ReturnBook")
646 print(" ")
647 bookId=int(input("EntertheBookIDtobeReturned:"))
648
649 #ExecuteSQLquerytochecktheissuestatusofthebook
650 c.execute("SELECT bookId FROM
651 books")result1=c.fetchall()
652 c.execute("SELECT issueStatus FROM books WHERE bookId=%s",
653 (bookId,))result2= c.fetchall()
654
655 db.commit()
656
657 if(bookId,)inresult1:
658 #Checkifthebookisissued
659 ifresult2[0][0]=="issued":
660 #ExecuteSQLqueriestoupdatebookdetailsandmarkitas

20|Page
661 returned
662 c.execute(
663 "UPDATEbooksSETreturnDate=CURRENT_DATEWHEREbookId=
664 %s",
665 (bookId,),
666 )
667 c.execute(
668 "UPDATEbooksSETreturnTime=CURRENT_TIMEWHEREbookId=
669 %s",
670 (bookId,),
671 )
672 c.execute(
673 "UPDATEbooksSETissueStatus='notissued'WHEREbookId=
674 %s",
675 (bookId,),
676 )
677 db.commit()
678 c.execute(
679 "selectissuedUserId,returnDate,returnTimefrombookswhere
680 bookId=%s",
681 (bookId,),
682 )
683 result=c.fetchall()
685
684 c.execute(
686 "UPDATEissuedBooksDetailsSETreturnDate=%s,returnTime
687 =%sWHEREuserId=%sANDbookId=%s",
688 (result[0][1],result[0][2],result[0][0],bookId),
689 )
690
691 db.commit()
692 c.execute(
693 "UPDATEbooksSETissuedUserId=NULLWHEREbookId=%s",
694 (bookId,)
695 )
696 db.commit()
697
698 print(f'The book of book id "{bookId}" is
699 returnedsuccessfully.')
700
701 c.execute("selectissueDatefrombooksWHEREbookId=%s",
702 (bookId,))
703 issueDate=c.fetchall()
704 c.execute("selectreturnDatefrombooksWHEREbookId=%s",
705 (bookId,))
706 returnDate =
707 c.fetchall()db.commit()
708
709 c.execute("UPDATEbooksSETissueDate=NULLWHEREbookId=
710 %s",(bookId,))
711 c.execute("UPDATEbooksSETissueTime=NULLWHEREbookId=
712 %s",(bookId,))
713 c.execute("UPDATEbooksSETreturnDate=NULLWHEREbookId=
714 %s",(bookId,))
715 c.execute("UPDATEbooksSETreturnTime=NULLWHEREbookId=
716 %s",(bookId,))
717 db.commit()
718
719 d1 = datetime.strptime(f"{issueDate[0][0]}", "%Y-%m-
720 %d")d2 = datetime.strptime(f"{returnDate[0][0]}", "%Y-%m-
721 %d")dateDifference= d1-d2
722
723 ifdateDifference.days>14:
724 extraDays = dateDifference.days -
725 14fine= extraDays*5
726 print("Fine(in Rs.) : ",
fine)c.execute(

21|Page
727 "update issuedBooksDetails set fineInRs=%s
728 whereuserId=%sand bookId=%s",
729 (fine,result[0][0],bookId),
730 )
731 db.commit()
732 else:
733 fine= 0*5
734 print("Fine(in Rs.) : ",
735 fine)c.execute(
736 "update issuedBooksDetails set fineInRs=%s
737 whereuserId=%sand bookId=%s",
738 (fine,result[0][0],bookId),
739 )
740 db.commit()
741
742 print("--------------------------")
743 returnBookMenu()
744 else:
745 #Notifytheuserthatthebookisnotissued
746 print(f'Thebookofbookid"{bookId}"isnotissuedbyany
747 user.')
748 print("--------------------------")
749 returnBookMenu()
750 else:
751 print(f"Book with book id {bookId} does not available in
752 thedigitallibrary.")
753 print(" ")
754 returnBookMenu()
755
756
757 #Functiontodisplaytheaddusermenuandhandleuserchoices
758 defaddUserMenu():
759 #Addusermenuoptions
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 #Userchoiceshandling
767 if userChoice ==
768 1:home()
769 elifuserChoice ==
770 2:modifyUser()
771 elifuserChoice ==
772 3:exiting()
773 else:
774 validOption()
775
776
777 #Functiontoaddanewuser
778 defaddUser():
779 print(" ")
780 print("AddUser")
781 print(" ")
782 #Getuserinputforuserdetails
783 userId = int(input("Enter the User ID :
784 "))userName=input("EntertheUserName:")
785 userPhoneNumber = input("Enter the User Phone Number :
786 ")userEmailId =input("Enter theUserEmail ID:
787 ")password=input("EntertheUserPassword:")
788 print(" ")
789
790 c.execute("SELECT userId FROM
791 users")result= c.fetchall()
792 db.commit()

22|Page
793
794 if (userId,) in
795 result:print(
796 f'The user of user number "{userId}" is already enrolled in
797 thedigitallibrary.'
798 )
799 print(" ")
800 addUserMenu()
801 else:
802 #ExecuteSQLquerytoinsertthenewuserintothedatabase
803 c.execute(
804 "INSERT INTO users (userId, userName, phoneNumber,
805 emailId,password)VALUES (%s,%s, %s, %s,%s)",
806 (userId,userName,userPhoneNumber,userEmailId,password),
807 )
808 db.commit()
809
810 #Notifytheuserthattheuserhasbeenaddedsuccessfully
811 print(" ")
812 print("User added
813 successfully!")print(" ")
814 addUserMenu()
815
816
817 #Functiontodisplaythedeleteusermenuandhandleuserchoices
818 defdeleteUserMenu():
819 #Deleteusermenuoptions
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 #Userchoiceshandling
827 if userChoice ==
828 1:home()
829 elifuserChoice ==
830 2:modifyUser()
831 elifuserChoice ==
832 3:exiting()
833 else:
834 validOption()
835
836
837 #Functiontodeleteauser
838 defdeleteUser():
839 print(" ")
840 print("DeleteUser")
841 print(" ")
842 #GetuserinputfortheuserIDtobedeleted
843 userId=int(input("EntertheUserID:"))
844 choice=input("AreyousuretodeletetheUser?(Yes/No):")
845
846 c.execute("SELECT userId FROM
847 users")result= c.fetchall()
848 db.commit()
849
850 if choice.lower() in ["yes",
851 "y"]:if(userId,) inresult:
852 c.execute("DELETE FROM users WHERE userId=%s",
853 (userId,))db.commit()
854
855 #Notifytheuserthattheuserhasbeendeletedsuccessfully
856 print("User deleted
857 successfully!")print("-----------")
858 deleteUserMenu()

23|Page
859 else:
860 print(
861 f'The user of user id "{userId}" does not enrolled in
862 thedigitallibrary.'
863 )
864 print("--------------------------")
865 deleteUserMenu()
866 elifchoice.lower() in ["no",
867 "n"]:print(" ")
868 print("UserNotDeleted!")
869 print("--------------------------")
870 deleteUserMenu()
871 else:
872 validOption()
873
874
875 #Functiontodisplaytheupdateusermenuandhandleuserchoices
876 defupdateUserMenu():p
877 rint("1.Home")
878 print("2.Back")
879 print("3.Exit")
880 userChoice=int(input("EnteryourChoicetoContinue:"))
881
882 #Userchoiceshandling
883 if userChoice ==
884 1:home()
885 elifuserChoice ==
886 2:updateUser()
887 elifuserChoice ==
888 3:exiting()
889 else:
890 validOption()
891
892
893 defnotUser(userId):
894 print(f'The user of user id "{userId}" does not enrolled in the
895 digitallibrary.')
896 print(" ")
897 updateBookMenu()
898
899
900 #Functiontoupdateuserdetails
901 defupdateUser():
902 print(" ")
903 print("UpdateUserDetails")print("
904 ")
905 # Display user update
906 optionsprint("1. Update the User
907 ID")print("2.UpdatetheUserName")
908 print("3. Update the User Phone
909 Number")print("4. Update the User Email
910 ID")print("5. Update the User
911 Password")print("6.Home")
912 print("7.Back")
913 print("8.Exit")
914 #Getuserchoice
915 userChoice = int(input("Enter your Choice to Continue :
916 "))print(" ")
917
918 c.execute("SELECT userId FROM
919 users")result= c.fetchall()
920 db.commit()
921
922 ifuserChoice==1:
923 #UpdateuserID
924 currentUserId=int(input("EntertheCurrentUserID:"))

24|Page
925 newUserId=int(input("EntertheNewUserID:"))
926
927 if (currentUserId,) in
928 result:c.execute(
929 "updateuserssetuserId=%swhereuserId=%s",(newUserId,
930 currentUserId)
931 )
932 db.commit()
933
934 print("User ID changed
935 Successfully!")print("-----------")
936 updateUserMenu()
937 else:
938 notUser(currentUserId)
939
940 elifuserChoice==2:
941 #Updateusername
942 userId = int(input("Enter the User ID :
943 "))newUserName=input("EntertheNewUserName:")
944
945 if (userId,) in
946 result:c.execute(
947 "update users set userName=%s where userId=%s",
948 (newUserName,userId)
949 )
950 db.commit()
951
952 print("User Name changed
953 Successfully!")print("-----------")
954 updateUserMenu()
955 else:
956 notUser(userId)
957
958 elifuserChoice==3:
959 #Updateuserphonenumber
960 userId = int(input("Enter the Current User ID :
961 "))newPhoneNumber=input("EntertheNewPhoneNumber:")
962
963 if (userId,) in
964 result:c.execute(
965 "update users set phoneNumber=%s where userId=%s",
966 (newPhoneNumber,userId),
967 )
968 db.commit()
969
970 print("User Phone Number changed
971 Successfully!")print("-----------")
972 updateUserMenu()
973 else:
974 notUser(userId)
975
976 elifuserChoice==4:
977 #UpdateuseremailID
978 userId = int(input("Enter the Current User ID :
979 "))newEmailId= input("EntertheNewEmailID:")
980
981 if (userId,) in
982 result:c.execute(
983 "updateuserssetemailId=%swhereuserId=%s",(newEmailId,
984 userId)
985 )
986 db.commit()
987
988 print("User Email ID changed
989 Successfully!")print("-----------")
990 updateUserMenu()

25|Page
991 else:
992 notUser(userId)
993
994 elifuserChoice==5:
995 #Updateuserpassword
996 userId = int(input("Enter the Current User ID :
997 "))newPassword=input("EntertheNewPassword:")
998 if (userId,) in
999 result:c.execute(
1000 "update users set password=%s where userId=%s",
1001 (newPassword,userId)
1002 )
1003 db.commit()
1004
1005 print("User Password changed
1006 Successfully!")print("-----------")
1007 updateUserMenu()
1008 else:
1009 notUser(userId)
1010
1011 elifuserChoice == 6:#
1012 Return to
1013 homehome()
1014 elifuserChoice==7:
1015 #Gobacktothepreviousmenu
1016 modifyUser()
1017 elifuserChoice==8:#
1018 Exit the
1019 programexiting()
1020 else:
1021 validOption()
1022
1023
1024 #Functiontomodifyuser
1025 defmodifyUser():
1026 print(" ")
1027 print("ModifyUser")
1028 print(" ")
1029 # Display user modification
1030 optionsprint("1.Add User")
1031 print("2. Delete
1032 User")print("3. Update User
1033 Details")print("4.Home")
1034 print("5.Back")
1035 print("6.Exit")
1036 #Getuserchoice
1037 userChoice = int(input("Enter your Choice to Continue :
1038 "))print(" ")
1039
1040 #Userchoiceshandling
1041 ifuserChoice==1:#
1042 Add a new
1043 useraddUser()
1044 elifuserChoice == 2:#
1045 Delete a
1046 userdeleteUser()
1047 elifuserChoice==3:
1048 #Updateuserdetails
1049 updateUser()
1050 elifuserChoice == 4:#
1051 Return to
1052 homehome()
1053 elifuserChoice==5:
1054 #Returntothepreviousmenu
1055 admin()
1056 elifuserChoice==6:

26|Page
1057 #Exittheprogram
1058 exiting()
1059 else:
1060 validOption()
1061
1062
1063 #Displayusersmenuoptions
1064 defdisplayUsersMenu():p
1065 rint("1.Home")
1066 print("2.Back")
1067 print("3.Exit")
1068 userChoice=int(input("EnteryourChoicetoContinue:"))
1069
1070 #Userchoiceshandling
1071 if userChoice ==
1072 1:home()
1073 elifuserChoice ==
1074 2:admin()
1075 elifuserChoice ==
1076 3:exiting()
1077 else:
1078 validOption()
1079
1080
1081 #Functiontodisplayallusers
1082 defdisplayUsers():
1083 print(" ")
1084 print("DisplayUsers")
1085 print("--------------------------")
1086 # Fetch all users from the
1087 databasec.execute("SELECT * FROM users ORDER BY
1088 userId")result= c.fetchall()
1089 db.commit()
1090
1091 ifresult:
1092 #Displayuserinformation
1093 print("Users enrolled in the Digital Library
1094 are :")i= 0
1095 for row in
1096 result:i+= 1
1097 r=length(i)
1098 print(f"{i}.UserID:{row[0]}")
1099 print(""*r+f"UserName:{row[1]}")
1100 print(""*r+f"PhoneNumber:{row[2]}")
1101 print(""*r+f"EmailID: {row[3]}")
1102 print(" " * r + f"Admin Status :
1103 {row[5]}")print("----------------")
1104 displayUsersMenu()
1105
1106 else:
1107 print("Nousersfound.")
1108 print("--------------------------")
1109 displayUsersMenu()
1110
1111
1112 #Searchusermenuoptions
1113 defsearchUsersMenu():p
1114 rint("1.Home")
1115 print("2.Back")
1116 print("3.Exit")
1117 userChoice=int(input("EnteryourChoicetoContinue:"))
1118
1119 #Userchoiceshandling
1120 if userChoice ==
1121 1:home()
1122 elifuserChoice==2:

27|Page
1123 searchUsers()
1124 elifuserChoice ==
1125 3:exiting()
1126 else:
1127 validOption()
1128
1129
1130 #FunctiontosearchusersbyID
1131 defsearchUsersbyId():
1132 print("--------------------------")
1133 print("Search Users by User
1134 ID")print(" ")
1135 #Get userIDto search
1136 userId=int(input("EntertheUserIDtosearchtheUser:"))
1137
1138 #Searchfortheuserinthedatabase
1139 c.execute("SELECT * FROM users WHERE userId=%s",
1140 (userId,))result= c.fetchall()
1141 db.commit()
1142
1143 ifresult:
1144 #Displayuserinformationiffound
1145 print(f'User enrolled in the Digital Library with the User
1146 ID"{userId}"is :')
1147 i=0
1148 for row in
1149 result:i+= 1
1150 r=length(i)
1151 print(f"{i}.UserID:{row[0]}")
1152 print(""*r+f"UserName:{row[1]}")
1153 print(""*r+f"PhoneNumber:{row[2]}")
1154 print(""*r+f"EmailID: {row[3]}")
1155 print(" " * r + f"Admin Status :
1156 {row[5]}")print("----------------")
1157 searchUsersMenu()
1158
1159 else:
1160 #Handlecasewhennouserisfound
1161 print(f'No user found with the user id
1162 "{userId}".')print(" ")searchUsersMenu()
1163
1164
1165 #Functiontosearchusersbykeyword
1166 defsearchUsersbyKeyword():
1167 print(" ")
1168 print("Search Users by
1169 Keyword")print(" ")
1170 #Getkeywordinputfromtheuser
1171 keyword=input("EnteraKeywordtosearchUsers:")
1172
1173 #Searchforuserswiththegivenkeywordintheirnames
1174 c.execute(
1175 "SELECT*FROMusersWHEREuserNameLIKE'%{}%'ORDERBY
1176 userId".format(keyword)
1177 )
1178 result =
1179 c.fetchall()db.commit
1180 ()
1181
1182 ifresult:
1183 #Displayuserinformationifusersarefound
1184 print(
1185 f'Users enrolled in the Digital Library with the
1186 Keyword"{keyword}"are :'
1187 )
1188 i=0

28|Page
1189 for row in
1190 result:i+= 1
1191 r=length(i)
1192 print(f"{i}.UserID:{row[0]}")
1193 print(""*r+f"UserName:{row[1]}")
1194 print(""*r+f"PhoneNumber:{row[2]}")
1195 print(""*r+f"EmailID: {row[3]}")
1196 print(" " * r + f"Admin Status :
1197 {row[5]}")print("----------------")
1198 searchUsersMenu()
1199
1200 else:
1201 #Handlecasewhennouserisfound
1202 print(f'No users found with the keyword
1203 "{keyword}".')print(" ")
1204 searchUsersMenu()
1205
1206
1207 #Functiontosearchusers
1208 defsearchUsers():
1209 print(" ")
1210 print("SearchUsers")
1211 print(" ")
1212 #Usersearchmenu
1213 print("1. Search by User
1214 ID")print("2. Search by
1215 Keyword")print("3.Home")
1216 print("4.Back")
1217 print("5.Exit")
1218 userChoice = int(input("Enter your Choice to Continue :
1219 "))print(" ")
1220
1221 #Userchoiceshandling
1222 if userChoice ==
1223 1:searchUsersbyId
1224 ()
1225 elifuserChoice ==
1226 2:searchUsersbyKeyword
1227 ()
1228 elifuserChoice ==
1229 3:home()
1230 elifuserChoice ==
1231 4:admin()
1232 elifuserChoice ==
1233 5:exiting()
1234 else:
1235 validOption()
1236
1237
1238 #Functiontomodifybooks
1239 defmodifyBook():
1240 print(" ")
1241 print("ModifyBook")
1242 print(" ")
1243 # Book modification
1244 menuprint("1. Add
1245 Book")print("2.DeleteBoo
1246 k")
1247 print("3. Update Book
1248 Details")print("4.Home")
1249 print("5.Back")
1250 print("6.Exit")
1251 userChoice = int(input("Enter your Choice to Continue :
1252 "))print(" ")
1253
1254 #Userchoiceshandling
if userChoice ==
1:addBook()
29|Page
e
l
i
f
u
s
e
r
C
h
o
i
c
e
=
=
2
:

30|Page
1255 deleteBook()
1256 elifuserChoice ==
1257 3:updateBook()
1258 elifuserChoice ==
1259 4:home()
1260 elifuserChoice ==
1261 5:admin()
1262 elifuserChoice ==
1263 6:exiting()
1264 else:
1265 validOption()
1266
1267
1268 #Functiontomanagenotes
1269 defnotes():
1270 print(" ")
1271 print("Notes")
1272 print(" ")
1273 # Display menu
1274 optionsprint("1. Modify
1275 Note")print("2. Display
1276 Notes")print("3. Search
1277 Notes")print("4.Home")
1278 print("5.Back")
1279 print("6.Exit")
1280 #Getuserchoice
1281 userChoice = int(input("Enter your Choice to Continue :
1282 "))print(" ")
1283
1284 #Handleuserchoices
1285 if userChoice ==
1286 1:modifyNote()
1287 elifuserChoice ==
1288 2:displayNotes()
1289 elifuserChoice ==
1290 3:searchNotes()
1291 elifuserChoice ==
1292 4:home()
1293 elifuserChoice ==
1294 5:user()
1295 elifuserChoice ==
1296 6:exiting()
1297 else:
1298 validOption()
1299
1300
1301 #Functiontodisplaytheaddnotemenuandhandleuserchoices
1302 defaddNoteMenu():print("1
1303 .Home")
1304 print("2.Back")
1305 print("3.Exit")
1306 #Getuserchoice
1307 userChoice=int(input("EnteryourChoicetoContinue:"))
1308
1309 #Handleuserchoices
1310 if userChoice ==
1311 1:home()
1312 elifuserChoice ==
1313 2:modifyNote()
1314 elifuserChoice ==
1315 3:exiting()
1316 else:
1317 validOption()
1318
1319
1320 #Functiontoaddnote

31|Page
1321 defaddNote():
1322 print(" ")
1323 print("AddNote")
1324 print(" ")
1325 #Getnotedetailsfromtheuser
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",
1332 (USERID,))result= c.fetchall()
1333 db.commit()
1334
1335 if (noteNumber,) in
1336 result:print(
1337 f'The note of note number "{noteNumber}" is already exists
1338 inthedigital library.'
1339 )
1340 print(" ")
1341 addNoteMenu()
1342
1343 else:
1344 #ExecuteSQLquerytoinsertthenoteintothedatabase
1345 c.execute(
1346 "INSERT INTO notes (userId, noteNumber,
1347 noteTitle,noteDescription, updateDate, updateTime) VALUES (%s,
1348 %s, %s, %s,CURRENT_DATE,CURRENT_TIME)",
1349 (USERID,noteNumber,noteTitle,noteDescription),
1350 )
1351 db.commit()
1352
1353 print(f'The note of note number "{noteNumber}" is
1354 addedsuccessfully.')
1355 print(" ")
1356 addNoteMenu()
1357
1358
1359 #Functiontodisplaythedeletenotemenuandhandleuserchoices
1360 defdeleteNoteMenu():
1361 #Displaymenuoptionsafterdeletingthenote
1362 print("1.Home")
1363 print("2.Back")
1364 print("3.Exit")
1365 #Getuserchoice
1366 userChoice = int(input("Enter your Choice to Continue :
1367 "))print(" ")
1368
1369 #Handleuserchoices
1370 if userChoice ==
1371 1:home()
1372 elifuserChoice ==
1373 2:modifyNote()
1374 elifuserChoice ==
1375 3:exiting()
1376 else:
1377 validOption()
1378
1379
1380 #Functiontodeleteanote
1381 defdeleteNote():
1382 print(" ")
1383 print("DeleteNote")
1384 print(" ")
1385 #Getnotenumbertobedeletedfromtheuser
1386 noteNumber=int(input("EntertheNoteNumbertoDeletetheNote:"))

32|Page
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",
1391 (USERID,))result= c.fetchall()
1392 db.commit()
1393
1394 if choice.lower() in ["yes",
1395 "y"]:if(noteNumber,)inresult:
1396 #ExecuteSQLquerytodeletethenotefromthedatabase
1397 c.execute(
1398 "delete FROM notes WHERE userId=%s and noteNumber=%s",
1399 (USERID,noteNumber),
1400 )
1401 db.commit()
1402
1403 print(f'The note of note number "{noteNumber}" is
1404 deletedsuccessfully.')
1405 print("--------------------------")
1406 deleteNoteMenu()
1407
1408 else:
1409 print(
1410 f'The note of note number "{noteNumber}" does not exists
1411 inthedigital library.'
1412 )
1413 print("--------------------------")
1414 deleteNoteMenu()
1415 elifchoice.lower() in ["no",
1416 "n"]:print(" ")
1417 print("NoteNotDeleted!")
1418 print(" ")
1419 deleteNoteMenu()
1420 else:
1421 validOption()
1422
1423
1424 #Functiontodisplaytheupdatenotesmenuandhandleuserchoices
1425 defupdateNotesMenu():p
1426 rint("1.Home")
1427 print("2.Back")
1428 print("3.Exit")
1429 #Getuserchoice
1430 userChoice = int(input("Enter your Choice to Continue :
1431 "))print(" ")
1432
1433 #Handleuserchoices
1434 if userChoice ==
1435 1:home()
1436 elifuserChoice ==
1437 2:updateNotes()
1438 elifuserChoice ==
1439 3:exiting()
1440 else:
1441 validOption()
1442
1443
1444 defnotNote(noteNumber):p
1445 rint(
1446 f'The note of note number "{noteNumber}" does not exists in
1447 thedigitallibrary.'
1448 )
1449 print(" ")
1450 updateNotesMenu()
1451
1452

33|Page
1453 #Functiontoupdateanote
1454 defupdateNotes():
1455 print(" ")
1456 print("UpdateNotes")
1457 print(" ")
1458 #Displayupdateoptions
1459 print("1. Update the Note
1460 Number")print("2. Update the Note
1461 Title")print("3. Update the Note
1462 Description")print("4.Home")
1463 print("5.Back")
1464 print("6.Exit")
1465 #Getuserchoice
1466 userChoice = int(input("Enter your Choice to Continue :
1467 "))print(" ")
1468
1469 c.execute("SELECT noteNumber FROM notes where userId=%s",
1470 (USERID,))result= c.fetchall()
1471 db.commit()
1472
1473 #Handleuserchoices
1474 ifuserChoice==1:
1475 #UpdateNoteNumber
1476 currentNoteNumber = int(input("Enter the Current Note Number :
1477 "))newNoteNumber= int(input("EntertheNewNoteNumber:"))
1478
1479 if (currentNoteNumber,) in
1480 result:# Update date and
1481 timec.execute(
1482 "update notes set updateDate=CURRENT_DATE where userId=
1483 %sandnoteNumber=%s",
1484 (USERID,currentNoteNumber),
1485 )
1486 c.execute(
1487 "update notes set updateTime=CURRENT_TIME where userId=
1488 %sandnoteNumber=%s",
1489 (USERID,currentNoteNumber),
1490 )
1491 #UpdateNoteNumber
1492 c.execute(
1493 "updatenotessetnoteNumber=%swhereuserId=%sand
1494 noteNumber=%s",
1495 (newNoteNumber,USERID,currentNoteNumber),
1496 )
1497 db.commit()
1498
1499 print("Note Number changed
1500 Successfully!")print("-----------")
1501 updateNotesMenu()
1502 else:
1503 notNote(currentNoteNumber)
1504
1505 elifuserChoice==2:
1506 #UpdateNoteTitle
1507 noteNumber = int(input("Enter the Current Note Number :
1508 "))newTitle= input("EntertheNewNoteTitle:")
1509
1510 if (noteNumber,) in
1511 result:# Update date
1512 and timec.execute(
1513 "update notes set updateDate=CURRENT_DATE where userId=
1514 %sandnoteNumber=%s",
1515 (USERID,noteNumber),
1516 )
1517 c.execute(
1518 "updatenotessetupdateTime=CURRENT_TIMEwhereuserId=%s

34|Page
1519 andnoteNumber=%s",
1520 (USERID,noteNumber),
1521 )
1522 #UpdateNoteTitle
1523 c.execute(
1524 "updatenotessetnoteTitle=%swhereuserId=%sand
1525 noteNumber=%s",
1526 (newTitle,USERID,noteNumber),
1527 )
1528 db.commit()
1529
1530 print("Note Title changed
1531 Successfully!")print("-----------")
1532 updateNotesMenu()
1533 else:
1534 notNote(noteNumber)
1535
1536 elifuserChoice==3:
1537 #UpdateNoteDescription
1538 noteNumber = int(input("Enter the Current Note Number :
1539 "))newDescription=input("EntertheNewNoteDescription:")
1540
1541 if (noteNumber,) in
1542 result:# Update date
1543 and timec.execute(
1544 "update notes set updateDate=CURRENT_DATE where userId=
1545 %sandnoteNumber=%s",
1546 (USERID,noteNumber),
1547 )
1548 c.execute(
1549 "update notes set updateTime=CURRENT_TIME where userId=
1550 %sandnoteNumber=%s",
1551 (USERID,noteNumber),
1552 )
1553 #UpdateNoteDescription
1554 c.execute(
1555 "updatenotessetnoteDescription=%swhereuserId=%sand
1556 noteNumber=%s",
1557 (newDescription,USERID,noteNumber),
1558 )
1559 db.commit()
1560
1561 print("Note Description changed
1562 successfully!")print("-----------")
1563 updateNotesMenu()
1564 else:
1565 notNote(noteNumber)
1566
1567 elifuserChoice ==
1568 5:home()
1569 elifuserChoice ==
1570 6:modifyNote()
1571 elifuserChoice ==
1572 7:exiting()
1573 else:
1574 validOption()
1575
1576
1577 #Functiontohandlenotemodifications
1578 defmodifyNote():
1579 print(" ")
1580 print("ModifyNotes")
1581 print(" ")
1582 # Display modification
1583 optionsprint("1.Add Note")
1584 print("2.DeleteNote")

35|Page
1585 print("3. Update
1586 Notes")print("4.Home")
1587 print("5.Back")
1588 print("6.Exit")
1589 #Getuserchoice
1590 userChoice = int(input("Enter your Choice to Continue :
1591 "))print(" ")
1592
1593 #Handleuserchoices
1594 if userChoice ==
1595 1:addNote()
1596 elifuserChoice ==
1597 2:deleteNote()
1598 elifuserChoice ==
1599 3:updateNotes()
1600 elifuserChoice ==
1601 4:home()
1602 elifuserChoice ==
1603 5:admin()
1604 elifuserChoice ==
1605 6:exiting()
1606 else:
1607 validOption()
1608
1609
1610 #Functiontodisplaythedisplaynotesmenuandhandleuserchoices
1611 defdisplayNotesMenu():p
1612 rint("1.Home")
1613 print("2.Back")
1614 print("3.Exit")
1615 userChoice = int(input("Enter your Choice to Continue :
1616 "))print(" ")
1617
1618 #Handleuserchoices
1619 if userChoice ==
1620 1:home()
1621 elifuserChoice ==
1622 2:user()
1623 elifuserChoice ==
1624 3:exiting()
1625 else:
1626 validOption()
1627
1628
1629 #Functiontodisplaynotes
1630 defdisplayNotes():
1631 # Fetchallnotesfromthe databasec.execute("SELECT *
1632 FROM notes ORDER BY noteNumber")result= c.fetchall()
1633 db.commit()
1634
1635 #Checkiftherearenotesavailable
1636 ifresult:
1637 print(f"Notes available in the Digital Library
1638 are :")i= 0
1639 for row in
1640 result:i+= 1
1641 r=length(i)
1642 print(f"{i}.NoteNumber:{row[1]}")
1643 print(" " * r + f"Note Title :
1644 {row[2]}")print(" " * r + f"Note Description :
1645 {row[3]}")print("" *r+f"UpdateDate: {row[4]}")
1646 print(" " * r + f"Update Time :
1647 {row[5]}")print("----------------")
1648 displayNotesMenu()
1649
1650

36|Page
1651 else:
1652 #Ifnonotesare found
1653 print("Nonotesfound.")
1654 print("--------------------------")
1655 displayNotesMenu()
1656
1657
1658 #Functiontodisplaythesearchnotesmenuandhandleuserchoices
1659 defsearchNotesMenu():p
1660 rint("1.Home")
1661 print("2.Back")
1662 print("3.Exit")
1663 userChoice=int(input("EnteryourChoicetoContinue:"))
1664
1665 #Handleuserchoices
1666 if userChoice ==
1667 1:home()
1668 elifuserChoice ==
1669 2:searchNotes()
1670 elifuserChoice ==
1671 3:exiting()
1672 else:
1673 validOption()
1674
1675
1676 #Functiontosearchnotesbynotenumber
1677 defsearchNotesbynoteNumber():
1678 #Getthenotenumbertosearch
1679 noteNumber=int(input("EntertheNoteNumbertosearchtheNote:"))
1680
1681 # Execute SQL query to fetch notes with the given note
1682 numberc.execute("SELECT * FROM notes WHERE bookId=%s",
1683 (noteNumber,))result= c.fetchall()
1684 db.commit()
1685
1686 #Checkifnotesarefound
1687 ifresult:
1688 print(
1689 f'Note available in the Digital Library with the Note
1690 Number"{noteNumber}"is :'
1691 )
1692 i=0
1693 for row in
1694 result:i+= 1
1695 r=length(i)
1696 print(f"{i}.NoteNumber:{row[1]}")
1697 print(" " * r + f"Note Title :
1698 {row[2]}")print(" " * r + f"Note Description :
1699 {row[3]}")print("----------------")
1700 searchNotesMenu()
1701
1702 else:
1703 # Ifnonotes arefoundwith thegivennote numberprint(f'No note
1704 found with the note number "{noteNumber}".')print(" ")
1705 searchNotesMenu()
1706
1707
1708 #Functiontosearchnotesbykeyword
1709 defsearchNotesbyKeyword():
1710 print(" ")
1711 print("Search Notes by
1712 Keyword")print(" ")
1713 #Getkeyword fromuser
1714 keyword=input("EnteraKeywordtosearchNotes:")
1715
1716

37|Page
1717 #ExecuteSQLquerytofetchnoteswiththegivenkeywordinthetitle
1718 c.execute(
1719 "SELECT*FROMnotesWHEREnoteTitleLIKE'%{}%'ORDERBY
1720 noteNumber".format(
1721 keyword
1722 )
1723 )
1724 result =
1725 c.fetchall()db.commit
1726 ()
1727
1728 #Checkifnotesarefound
1729 ifresult:
1730 print(
1731 f'Notes available in the Digital Library with the
1732 Keyword"{keyword}"are :'
1733 )
1734 i=0
1735 for row in
1736 result:i+= 1
1737 r=length(i)
1738 print(f"{i}.NoteNumber:{row[1]}")
1739 print(" " * r + f"Note Title :
1740 {row[2]}")print(" " * r + f"Note Description :
1741 {row[3]}")print("----------------")
1742 searchNotesMenu()
1743
1744 else:
1745 # If no notes are found with the given
1746 keywordprint(f'No notes found with the keyword
1747 "{keyword}".')print(" ")
1748 searchNotesMenu()
1749
1750
1751 #Functiontohandlenotesearching
1752 defsearchNotes():
1753 print(" ")
1754 print("SearchNotes")
1755 print(" ")
1756 #Displaysearchoptionsprint("1.
1757 Search by Note Number")print("2.
1758 Search by
1759 Keyword")print("3.Home")
1760 print("4.Back")
1761 print("5.Exit")
1762 #Getuserchoice
1763 userChoice = int(input("Enter your Choice to Continue :
1764 "))print(" ")
1765
1766 #Handleuserchoices
1767 if userChoice ==
1768 1:searchNotesbynoteNumber()
1769 elifuserChoice ==
1770 2:searchNotesbyKeyword
1771 ()
1772 elifuserChoice ==
1773 3:notes()
1774 elifuserChoice ==
1775 4:modifyNote()
1776 elifuserChoice ==
1777 5:exiting()
1778 else:
1779 validOption()
1780
1781
1782 #Functiontodisplaythechangeadminmenuandhandleuserchoices
defchangeAdminMenu():p
rint("1.Home")
38|Page
1783 print("2.Back")
1784 print("3.Exit")
1785 userChoice = int(input("Enter your Choice to Continue :
1786 "))print(" ")
1787
1788 #Handleuserchoices
1789 if userChoice ==
1790 1:home()
1791 elifuserChoice ==
1792 2:admin()
1793 elifuserChoice ==
1794 3:exiting()
1795 else:
1796 validOption()
1797
1798
1799 #Functiontochangetheadminstatus
1800 defchangeAdmin():
1801 print(" ")
1802 print("ChangeAdmin")
1803 print(" ")
1804 #Getnewadmin'sIDandpasswordfromtheuser
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 #CheckiftheentereduserIDexists
1811 c.execute("SELECT password FROM users WHERE userId=%s",
1812 (newAdminId,))result= c.fetchall()
1813 db.commit()
1814
1815 #Checktheuser'schoicetoproceedorcancel
1816 ifchoice.lower()in["yes","y"]:
1817 #IftheuserIDisnotvalid,printanerrormessage
1818 iflen(result)==0:
1819 print("Please enter a valid user
1820 id!")else:
1821 #Iftheenteredpasswordmatchestheuser'spassword
1822 ifnewAdminPassword==result[0][0]:
1823 #Updateadminstatusforallusers
1824 c.execute(
1825 "UPDATE users SET adminStatus='not admin'
1826 WHEREadminStatus='admin'"
1827 )
1828 c.execute(
1829 "UPDATEusersSETadminStatus='admin'WHEREuserId
1830 =%s",
1831 (newAdminId,),
1832 )
1833 db.commit()
1834
1835 print("Admin Changed
1836 Successfully!")print("-----------")
1837 changeAdminMenu()
1838
1839 else:
1840 print("Please enter a valid
1841 password!")elifchoice.lower() in["no", "n"]:
1842 print("AdminNotChanged!")
1843 print(" ")
1844 changeAdminMenu()
1845 else:
1846 validOption()
1847
1848

39|Page
1849 #Functiontoauthenticateadmin
1850 defauthAdmin():
1851 print(" ")
1852 print("Admin
1853 Authentication")print(" ")
1854 adminId = int(input("Enter the Admin's User ID :
1855 "))adminPassword=input("EntertheAdmin'sUserPassword:")
1856
1857 #CheckiftheenteredadminIDexists
1858 c.execute("SELECT password FROM users WHERE userId=%s",
1859 (adminId,))result= c.fetchall()
1860 db.commit()
1861
1862 #IftheenteredadminIDisnotvalid,printanerrormessage
1863 iflen(result)==0:
1864 print(" ")pri
1865 nt("Please enter a valid user
1866 id!")print(" ")
1867 else:
1868 #Iftheenteredpasswordmatchestheadmin'spassword
1869 ifadminPassword==result[0][0]:
1870 global
1871 USERIDUSERID=admin
1872 Id
1873 print("\033[0;35m--------------------------\033[0;0m")
1874 print("\033[0;36mAdmin is verified successfully.\
1875 033[0;0m")print("\033[0;35m----------------\033[0;0m")
1876 admin()#Calltheadminmenu
1877 else:
1878 print("Please enter a valid
1879 password!")print("---------------")
1880
1881
1882 #Functiontodisplaytheadminmenu
1883 defadmin():
1884 print(" ")
1885 print("Admin")
1886 print(" ")
1887 print("1.Login into User
1888 Panel")print("2.Modify User")
1889 print("3.Display
1890 Users")print("4.Search
1891 Users")print("5.Modify
1892 Book")print("6.Issue
1893 Book")print("7.Return
1894 Book")print("8.Change
1895 Admin")print("9.Home")
1896 print("10.Back")
1897 print("11.Exit")
1898 userChoice = int(input("Enter your Choice to Continue :
1899 "))print(" ")
1900
1901 #Handleuserchoices
1902 ifuserChoice==1:
1903 print("You are successfully login into user
1904 panel.")print(" ")
1905
1906 user()
1907 elifuserChoice ==
1908 2:modifyUser()
1909 elifuserChoice ==
1910 3:displayUsers()
1911 elifuserChoice ==
1912 4:searchUsers()
1913 elifuserChoice ==
1914 5:modifyBook()
elifuserChoice==6:

40|Page
1915 issueBook()
1916 elifuserChoice ==
1917 7:returnBook()
1918 elifuserChoice ==
1919 8:changeAdmin()
1920 elifuserChoice ==
1921 9:home()
1922 elifuserChoice ==
1923 10:authAdmin()
1924 elifuserChoice ==
1925 11:exiting()
1926 else:
1927 validOption()
1928
1929
1930 #Functiontoauthenticateauser
1931 defauthUser():
1932 print(" ")
1933 print("UserAuthentication")print("
1934 ")
1935 userId = int(input("Enter the User ID :
1936 "))password=input("EntertheUserPassword:")
1937
1938 #CheckiftheentereduserIDexists
1939 c.execute("SELECT password FROM users WHERE userId=%s",
1940 (userId,))result= c.fetchall()
1941 db.commit()
1942
1943 #IftheentereduserIDisnotvalid,printanerrormessage
1944 iflen(result)==0:
1945 print(" ")pri
1946 nt("Please enter a valid user
1947 id!")print(" ")
1948 else:
1949 #Iftheenteredpasswordmatchestheuser'spassword
1950 ifpassword==result[0][0]:
1951 global
1952 USERIDUSERID=userI
1953 d
1954 print("\033[0;35m--------------------------\033[0;0m")
1955 print("\033[0;36mUser is verified successfully.\
1956 033[0;0m")print("\033[0;35m----------------\033[0;0m")
1957 user()#Calltheusermenu
1958 else:
1959 print("Please Enter a Valid
1960 Password!")print("---------------")
1961
1962
1963 #Functiontosearch&displaythewikipediaarticles
1964 defwikipediaArticles():
1965 #Functiontofetcharticledetails
1966 deffetchingArticle(keyword,articleLength=1500):
1967 #CreatingaWikipediaAPIobject
1968 wiki = wikipediaapi.Wikipedia(language="en", user_agent="digital-
1969 library/1.1")
1970 #Fetchingthepageforthegivensearchquery
1971 page=wiki.page(keyword)
1972
1973 #Checkingifthepageexists
1974 if not
1975 page.exists():pri
1976 nt(
1977 f'Sorry, the Wikipedia Article for the keyword
1978 "{keyword}"doesnot exists.'
1979 )
1980 print("--------------------------")
else:
#Displayingarticletitle
41|Page
1981 print("Title:")
1982 print(page.title)
1983 print("URL:")
1984 print(page.fullurl)
1985 #Displayingasummaryofthearticlewithinthespecified
1986 length
1987 print("Summary:")
1988
1989 start= 0
1990 end=157
1991 article=page.summary[:articleLength]
1992
1993 whileend<=articleLength:
1994 print(article[start:end])
1995 start+=157
1996 end+= 157
1997 else:
1998 print("--------------------------")
2000
1999
print(" ")
2001 print("SearchArticles")
2002 print("--------------------------")
2003 #Takinguserinputforthekeywordandarticlelength
2004 keyword=input("EntertheKeywordforsearchingtheWikipediaArticle
2005 : ")
2006 articleLength=int(input("EntertheArticleLength:"))
2007 print(" ")
2008
2009 #Callingthefunctiontofetchanddisplaythearticle
2010 fetchingArticle(keyword,
2011
2012 articleLength)userMenu()
2013
2014
2015 #Functiontosearch&displaythenews
2016 def news():
2017 deffetchNews(apiKey,country="in",category="science",numArticles=5):url=
2018 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 ifresponse.status_code==200:
2028 news_data=response.json()
2029 articles=news_data.get("articles",[])
2030
2031 fori,articleinenumerate(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
2044 print("
print("News") ")
2045 print(" ")
2046 print("Countrycodesare:")

42|Page
2047 print("https://newsapi.org/
2048 sources")print("Categoriesare:")
2049 print("business, entertainment, general, health, science,
2050 sports,technology")
2051 print(" ")
2052 country = input("Enter the Country Code :
2053 ")category=input("EntertheCategory:")
2054 numArticles = int(input("Enter the Number of Articles :
2055 "))print(" ")
2056
2057 fetchNews(API_KEY, country, category,
2058
2059 numArticles)userMenu()
2060
2061
2062 #Functiontodisplaytheissuedbooksdetailsofauser
2063 defissuedBooksDetails():
2064 print(" ")
2065 print("Issued Books
2066 Details")print(" ")
2067 returnPolicy()
2068
2069 c.execute(
2070 "SELECT * FROM issuedBooksDetails WHERE userId=%s ORDER BY bookId",
2071 (USERID,)
2072 )
2073 result =
2074 c.fetchall()db.commit
2075 ()
2076
2077 ifresult==[]:
2078 print("NoBooksIssued!")
2079 print("--------------------------")
2080 userMenu()
2081
2082 else:
2083 i=0
2084 for row in
2085 result:i+= 1
2086 r=length(i)
2087 print(f"{i}.BookID:",row[1])
2088 print("" *r+"BookName:",row[2])
2089 print(""*r+"IssueDate:",row[3])
2090 print(""*r+"IssueTime:",row[4])
2091 print(""*r+"ReturnDate:",row[5])
2092 print(""*r+"ReturnTime:",row[6])
2093 print(" " * r + "Fine(in Rs.) : ",
2094 row[7])print("-------------------")
2095 userMenu()
2096
2097
2098 #Functiontodisplaytheusermenu
2099 defuser():
2100 print(" ")
2101 print("User")
2102 print(" ")
2103 #CheckiftheentereduserIDexists
2104 c.execute('SELECT userId FROM users WHERE
2105 adminStatus="admin"')result= c.fetchall()
2106 db.commit()
2107
2108 ifresult[0][0]==USERID:
2109 print("1.Login into Admin
2110 Panel")print("2.About the
2111 Library")print("3.News")
2112 print("4.Wikipedia
Articles")print("5.DisplayBooks
")
43|Page
2113 print("6.Search
2114 Books")print("7.Issued Books
2115 Details")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 #Handleuserchoices
2123 ifuserChoice==1:
2124 print("You are successfully login into admin
2125 panel.")print("------------------")
2126
2127 admin()
2128 elifuserChoice ==
2129 2:aboutLibrary()
2130 elifuserChoice ==
2131 3:news()
2132 elifuserChoice ==
2133 4:wikipediaArticles
2134 ()
2135 elifuserChoice ==
2136 5:displayBooks()
2137 elifuserChoice ==
2138 6:searchBooks()
2139 elifuserChoice ==
2140 7:issuedBooksDetails
2141 ()
2142 elifuserChoice ==
2143 8:notes()
2144 elifuserChoice ==
2145 9:home()
2146 elifuserChoice ==
2147 10:authUser()
2148 elifuserChoice ==
2149 11:exiting()
2150 else:
2151 validOption()
2152 else:
2153 print("1.About
2154 Library")print("2.News")
2155 print("3.Wikipedia
2156 Articles")print("4.Display
2157 Books")print("5.Search
2158 Books")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 #Handleuserchoices
2167 if userChoice ==
2168 1:aboutLibrary(
2169 )
2170 elifuserChoice ==
2171 2:news()
2172 elifuserChoice ==
2173 3:wikipediaArticles
2174 ()
2175 elifuserChoice ==
2176 4:displayBooks()
2177 elifuserChoice ==
2178 5:searchBooks()
elifuserChoice ==
6:issuedBooksDetails
44|Page
(
)
elif
u
s
e
r
C
h
o
i
c
e

=
=

7
:
n
o
t
e
s
(
)

45|Page
2179 elifuserChoice==8:
2180 home()
2181 elifuserChoice ==
2182 9:authUser()
2183 elifuserChoice ==
2184 10:exiting()
2185 else:
2186 validOption()
2187
2188
2189 #Functiontodisplaythemainmenu
2190 defhome():
2191 whileTrue:
2192 print("==========================")
2193 print("\033[1;32m~~~~~~~~~~~~~~~~~~~~~~~~~~\
2194 033[0;0m")print(
2195 "\033[1;31m"
2196 +pyfiglet.figlet_format("Welcometothe",font="banner3",
2197 width=1000)
2198 )
2199 print(
2200 pyfiglet.figlet_format("DigitalLibrary",font="banner3",
2201 width = 1000)
2202 +"\033[0;0m"
2203 )
2204 Print("\033[1;32m~~~~~~~~~~~~~~~~~~~~~~~~~~\
2205 033[0;0m")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 #Handleuserchoices
2216 if user Choice ==
2217 1:authAdmin()
2218 elif user Choice ==
2219 2:authUser()
2220 elif user Choice ==
2221 3:exiting()
2222 else:
2223 validOption()
2224
2225
2226 #Callthemainmenufunction
2227 home()
2228
2229

46|Page
MYSQL
DATABASES

47|Page
MYSQL DATABASE

Library Database:

Books Table:

Users Table:

48|Page
Notes Table:

Issued Books Details Table:

49|Page
OUTPUTS

50|Page
OUTPUT

Starting of the program:

Admin Authentication:

Adding anewuser:

51|Page
Updating user details:

Adding anewbook:

52|Page
Updating book details:

53|Page
User Authentication:

About Library:

54|Page
News:

Wikipedia Articles:

55|Page
Issued Books Details:

56|Page
Existing the program:

3|Page
HARDWARES AND SOFTWARES REQUIRED

HARDWARES
1. Desk top Computer/Laptop
2. Mobile Phone

SOFTWARES
1. Python (Latest Version)
2. MySQL
3. My SQL-Connector- Python, Requests, Wikipedia-
API, Date time, Py fig let Modules

4|Page
5|Page
REFERENCES

1.NewsAPI
https://newsapi.org/
2. Wikipedia
https://www.wikipedia.org/
3. Python
https://www.python.org/
4. MySQL https://www.mysql.com/
5. ANSIES cape Codes in Python

 https://pypi.org/project/ansi/

 https://replit.com/talk/learn/ANSI-Escape-Codes-in-Python/22803

 https://gist.github.com/rene-d/9e584a7dd2935d0f461904b9f2950007
6. Class 11th&12thComputerScienceArihantBooks

6|Page
7|Page

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