Ip Docs
Ip Docs
Ip Docs
Session: 2023-24
Subject: Informatics Practices
Topic: Library Management System
1 Acknowledgment
2 Certificate
4 Benefits
5 MySQL Tables
6 Source Code
7 Output
8 Bibliography
CERTIFICATE
Signature of Signature of
Internal Examiner External Examiner
ACKNOWLEDGEMENT
In Conclusion:
The Library Management System stands as a technological
cornerstone in the realm of library administration. By blending
efficiency with accessibility, it aims to elevate the standard of
library services, fostering a culture of knowledge acquisition and
community engagement.
MySQL tables
Tables used:
1) Books
2) Members
3) IssuedBookList
Source Code
import pandas as pd
import mysql.connector
from tabulate import tabulate
from datetime import date
#-------------------------------------------------------------------------------------------------------------------------------------
def AddBookDetails(self):
print("Preparing for new Entry..")
EnteredBookIDs = pd.read_sql("select BookId from Books;", mycon)
#-------------------------------------------------------------------------------------------------------------------------------------
def DeleteBookDetails(self):
AllBookEntries=pd.read_sql("select * from Books;",mycon)
print(tabulate(AllBookEntries, headers='keys', tablefmt = 'psql', showindex=False))
#-------------------------------------------------------------------------------------------------------------------------------------
def SearchBook(self):
SearchField=int(input("\nBy which field do you want to search the book\n1. ID\n2. Book Name\n3.
Author\n4. Price range\n>>"))
if SearchField==1:
EnteredBookIDs = pd.read_sql("select BookId from Books;", mycon)
while True:
BookId=int(input("Enter Book Id: "))
if BookId not in EnteredBookIDs.values:
print("ID not found in the list.. \nTry again? (Y/N): ")
LeaveChoiceFunc()
else:
SearchBookByID = pd.read_sql("select * from Books where BookId={}".format(BookId),mycon)
print(tabulate(SearchBookByID,headers='keys',tablefmt = 'psql', showindex=False))
break
elif SearchField==2:
BookName = input("Enter the Book Name: ")
SearchBookByName = pd.read_sql("select * from Books where
BookName='{}'".format(BookName),mycon)
print(tabulate(SearchBookByName,headers='keys',tablefmt = 'psql', showindex=False))
elif SearchField==3:
Author = input("Enter the Author's Name: ")
SearchBookByAuthor = pd.read_sql("select * from Books where Author='{}'".format(Author),mycon)
print(tabulate(SearchBookByAuthor,headers='keys',tablefmt = 'psql', showindex=False))
elif SearchField==4:
MinBookPrice = int(input("Enter the min Price of Book: "))
MaxBookPrice = int(input("Enter max Price of Book: "))
SearchBookByPrice = pd.read_sql("select * from Books where Price>{} and
Price<{}".format(MinBookPrice,MaxBookPrice),mycon)
if SearchBookByPrice.empty==True:
print("No Books found under the given range..")
return
print(tabulate(SearchBookByPrice,headers='keys',tablefmt = 'psql', showindex=False))
else:
print("\nInvalid Field...\n\n")
self.SearchBook()
FuncOverExitOrNo()
#-------------------------------------------------------------------------------------------------------------------------------------
def EditBookEntry(self):
EnteredBookIDs = pd.read_sql("select BookId from Books;", mycon)
EntryToBeEdited = int(input("Enter the Book ID of the entry you want to edit: "))
if EntryToBeEdited not in EnteredBookIDs.values:
print("\nEntry not found\n\n")
self.EditBookEntry()
return
else:
EntryBackup = pd.read_sql("select * from Books where BookId={}".format(EntryToBeEdited),mycon)
NewBookId = input("Enter new Book ID (Enter '-' to use old value): ")
if NewBookId != '-':
if int(NewBookId) in EnteredBookIDs.values:
print("\nBookID already exists...\n\n")
self.EditBookEntry()
return
else:
NewBookName = input("Enter new Book Name (Enter '-' to use old value): ")
NewAuthor = input("Enter new Authors Name (Enter '-' to use old value): ")
NewPrice = input("Enter new Price (Enter '-' to use old value): ")
NewCopies = input("Enter new No. of Copies available (Enter '-' to use old value): ")
Data = [NewBookId,NewBookName,NewAuthor,NewPrice,NewCopies]
DataToBeEntered=[]
for i in range (len(Data)):
if Data[i]=='-':
DataToBeEntered.append(EntryBackup.iat[0,i])
else:
DataToBeEntered.append(Data[i])
DataToBeEntered[-1]=intfloat(DataToBeEntered[-1])
DataToBeEntered[-2]=float(DataToBeEntered[-2])
UpdateQuery = "update Books set BookId = {}, BookName ='{}', Author = '{}', Price = {}, CopiesAvailable = {} where
BookId={}".format(DataToBeEntered[0],DataToBeEntered[1],
DataToBeEntered[2],DataToBeEntered[3],
DataToBeEntered[4],DataToBeEntered[0])
cursor.execute(UpdateQuery)
mycon.commit()
print("Entry Updated successfully!")
FuncOverExitOrNo()
#-------------------------------------------------------------------------------------------------------------------------------------
BookOptions = {1 : ShowBookDetails,
2 : SearchBook,
3 : AddBookDetails,
4 : EditBookEntry,
5 : DeleteBookDetails}
#-------------------------------------------------------------------------------------------------------------------------------------
def BookOperationsNavigator(self):
B_Obj=BookOperations()
Navi = int(input("\n1. Show Book List \n2. Search Book List \n3. Add Book Details \n4. Edit Book Entry \
n5. Delete Book Entry \n6. Main Menu \n>>"))
if Navi == 6:
MainMenu()
else:
B_Obj.BookOptions[Navi](self)
#-------------------------------------------------------------Members------------------------------------------------------------
class MemberOperations:
def ShowMemberDetails(self):
AllMemberEntries=pd.read_sql("select * from Members;",mycon)
print(tabulate(AllMemberEntries, headers='keys', tablefmt = 'psql', showindex=False))
FuncOverExitOrNo()
def AddMemberDetails(self):
print("Preparing for new Entry..")
EnteredMemberIDs = pd.read_sql("select MemberId from Members;", mycon)
#-------------------------------------------------------------------------------------------------------------------------------------
def EditMemberEntry(self):
EnteredMemberIDs = pd.read_sql("select MemberId from Members;", mycon)
while True:
EntryToBeEdited = int(input("Enter the Member ID of the entry you want to edit: "))
if EntryToBeEdited not in EnteredMemberIDs.values:
print("\nEntry not found \nTry again? (Y/N): ")
LeaveChoiceFunc()
else:
EntryBackup = pd.read_sql("select * from Members where
MemberId={}".format(EntryToBeEdited),mycon)
NewMemberId = input("Enter new Member ID (Enter '-' to use old value): ")
if NewMemberId != '-':
if int(NewMemberId) in EnteredMemberIDs.values:
print("\nMember ID already exists... \n")
self.EditMemberEntry()
return
else:
NewMemberName = input("Enter new Member's Name (Enter '-' to use old value): ")
NewPhone = input("Enter new Phone No.[10 digits] (Enter '-' to use old value): ")
Data = [NewMemberId,NewMemberName,NewPhone]
DataToBeEntered=[]
for i in range (len(Data)):
if Data[i]=='-':
DataToBeEntered.append(EntryBackup.iat[0,i])
else:
DataToBeEntered.append(Data[i])
DataToBeEntered[-1]=int(DataToBeEntered[-1])
UpdateQuery = "update Members set MemberId = {}, MemberName ='{}', Phone = {} where
MemberId={}".format(DataToBeEntered[0],DataToBeEntered[1],
DataToBeEntered[2],DataToBeEntered[0])
cursor.execute(UpdateQuery)
mycon.commit()
print("Entry Updated successfully!")
FuncOverExitOrNo()
#-------------------------------------------------------------------------------------------------------------------------------------
def SearchMember(self):
SearchField=int(input("\nBy which field do you want to search \n1. ID\n2. Member Name\n3. Phone\
n>>"))
if SearchField==1:
EnteredMemberIDs = pd.read_sql("select MemberId from Members;", mycon)
while True:
MemberId=int(input("Enter Member Id: "))
if MemberId not in EnteredMemberIDs.values:
print("ID not found..\n")
LeaveChoice = input("Leave? (Y/N): ")
if LeaveChoice == 'Y'or LeaveChoice == 'y':
FuncOverExitOrNo()
else: continue
else:
SearchMemberByID = pd.read_sql("select * from Members where
MemberId={}".format(MemberId),mycon)
print(tabulate(SearchMemberByID,headers='keys',tablefmt = 'psql', showindex=False))
break
elif SearchField==2:
MemberName = input("Enter the Member's Name: ")
SearchMemberByName = pd.read_sql("select * from Members where
MemberName='{}'".format(MemberName),mycon)
print(tabulate(SearchMemberByName,headers='keys',tablefmt = 'psql', showindex=False))
elif SearchField==3:
Phone=int(input("Enter the Phone No.: "))
SearchMemberByPhone = pd.read_sql("select * from Members where
Phone={}".format(Phone),mycon)
print(tabulate(SearchMemberByPhone,headers='keys',tablefmt = 'psql', showindex=False))
else:
print("\nInvalid Field...\n\n")
self.SearchMember()
FuncOverExitOrNo()
#-------------------------------------------------------------------------------------------------------------------------------------
def DeleteMemberDetails(self):
AllMemberEntries=pd.read_sql("select * from Members;",mycon)
print(tabulate(AllMemberEntries, headers='keys', tablefmt = 'psql', showindex=False))
while True:
MemberIdToBeRemoved = int(input("Enter the Member Id which is to be removed: "))
if MemberIdToBeRemoved in EnteredMemberIDs.values:
Confirmation = input("Are you sure you want to delete this Entry(Y/N): ")
if Confirmation=='y'or Confirmation=='Y':
insert_query = "delete from Members where MemberId={}".format(MemberIdToBeRemoved)
cursor.execute(insert_query)
mycon.commit()
break
elif Confirmation == 'n'or Confirmation == 'N':
print("Aborting..")
return
else:
print("Member ID not found..")
continue
print("Entry deleted successfully!")
FuncOverExitOrNo()
MemberOptions = {1 : ShowMemberDetails,
2 : SearchMember,
3 : AddMemberDetails,
4 : EditMemberEntry,
5 : DeleteMemberDetails}
#-------------------------------------------------------------------------------------------------------------------------------------
def MemberOperationsNavigator(self):
M_Obj=MemberOperations()
Navi = int(input("\n1. Show Member List \n2. Search Member List \n3. Add Member Details \n4. Edit
Member Entry \n5. Delete Member Entry \n6. Main Menu \n>>"))
if Navi == 6:
MainMenu()
else:
M_Obj.MemberOptions[Navi](self)
#------------------------------------------------------------Issue-------------------------------------------------------------------
class IssueOperations:
#-------------------------------------------------------------------------------------------------------------------------------------
def IssueABook(self):
while True:
MemberId = int(input("Enter Member Id: "))
if MemberId not in EnteredMemberIDs.values:
print("Member Id not found..\n\nTry again? (Y/N) \n>>")
LeaveChoiceFunc()
else:
IssueChoice = int(input("Enter the Id of the book you want to issue: "))
if IssueChoice in EnteredBookIDs.values:
IssueCount = int(input("Enter the no. of copies to be issued: "))
AvailableBookCopies = pd.read_sql("select CopiesAvailable from Books where BookId =
{};".format(IssueChoice), mycon)
AvailableBookCopies = AvailableBookCopies.at[-0,'CopiesAvailable']
if AvailableBookCopies >= IssueCount:
IssueId = GetLastIssueId+1
IssueDate = str(date.today())
IssueDate = IssueDate.replace('-','')
ReturnPeriod = int(input("Enter the No. of days for which you want to issue (Min: 1 week, Max
1 month): "))
if ReturnPeriod <7 or ReturnPeriod >31:
print("Invalid issue period..\n\n Try again? (Y/N) \n>>")
ChoiceFunc()
else:
DateToReturn = int(IssueDate)+ReturnPeriod
IssueDate,DateToReturn = str(IssueDate), str(DateToReturn)
PendingCheck = pd.read_sql("""select IssueId, case when DateToReturn>curdate() then 'Not Pending' else
'Pending' end as ReturnStatus
from IssuedBookList
where IssueId = {};""".format(IssueId),mycon)
LateFeePerDay = 1.5
CurDate, DateToReturn = date.today(), IssuedBookEntry.at[0,'DateToReturn']
if PendingCheck.at[0,'ReturnStatus'] == 'Pending':
DaysLateCount = (CurDate-DateToReturn).days
LateFeePayable = DaysLateCount * LateFeePerDay
print(f"You are {DaysLateCount} days late. \nLate Fees will be charged accordingly, calculating amount...\n")
#-------------------------------------------------------------------------------------------------------------------------------------
IssueClassOptions = {1 : IssuedBooksDetails,
2 : IssueABook,
3 : ReturnABook}
#-------------------------------------------------------------------------------------------------------------------------------------
def IssueOperationsNavigator(self):
I_Obj=IssueOperations()
Navi = int(input("\n1. Details of Issued Books \n2. Issue a Book \n3. Return a Book \n4. Main Menu \
n>>"))
if Navi == 4:
MainMenu()
else:
I_Obj.IssueClassOptions[Navi](self)
#-------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------Main Menu-------------------------------------------------------------
def LeaveChoiceFunc():
LeaveChoice = input()
if LeaveChoice == 'Y'or LeaveChoice == 'y':
return # CONTINUE
else:
FuncOverExitOrNo()
return False # BREAK
#-------------------------------------------------------------------------------------------------------------------------------------
def FuncOverExitOrNo():
ContinueOrNo = int(input("\n1. Return to Main Menu \n2. Close program \n>>"))
if ContinueOrNo == 1:
MainMenu()
else:
mycon.close()
quit()
#-------------------------------------------------------------------------------------------------------------------------------------
def MainMenu():
print("Enter your choice")
MainMenuChoice = int(input("\n1. Book List operations \n2. Member List operations \n3. Issued Book
details \n4. Quit \n>>"))
if MainMenuChoice == 1:
BO.BookOperationsNavigator()
elif MainMenuChoice == 2:
MO.MemberOperationsNavigator()
elif MainMenuChoice == 3:
IO.IssueOperationsNavigator()
elif MainMenuChoice == 4:
mycon.close()
quit()
#-------------------------------------------------------------------------------------------------------------------------------------
BO = BookOperations()
MO = MemberOperations()
IO = IssueOperations()
#-------------------------------------------------------------------------------------------------------------------------------------
MainMenu()
Output
1. Book List Operations:
I. Showing Book List
II. Searching Book List
a) By ID:
b) By Book Name:
c) By Author:
d) By Price range:
III. Adding Book Details
In SQL:
IV. Editing Book entry
In MySQL:
V. Deleting an entry
In MySQL:
c) By Phone
III. Adding Member Details
In MySQL:
In MySQL:
3. Issued Book Details
I. Details of Issued Books
II. Issuing a Book
In MySQL:
In MySQL:
Entry of the book in IssuedBookList table before returning:
1. stackoverflow.com
2. geeksforgeeks.org
3. wikipedia.org
4. docs.python.org