-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlibrary.py
208 lines (189 loc) · 6.2 KB
/
library.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import pandas as pd
import matplotlib.pyplot as plt
from datetime import date
def addNewBook():
bookid = int(input("Enter a book id : "))
title = input("Enter book title : ")
author = input("Enter author of the book : ")
publisher = input("Enter book publisher : ")
edition = input("Enter edition of book : ")
cost = int(input("Enter cost of the book : "))
category = input("Enter category of book : ")
bdf = pd.read_csv("books.csv")
n = bdf["bookid"].count()
bdf.at[n] = [bookid,title,author,publisher,edition,cost,category]
bdf.to_csv("books.csv",index = False)
print("Book added successfully")
def login():
uname = input("Enter Username : ")
pwd = input("Enter Password : ")
df = pd.read_csv("users.csv")
df = df.loc[df["username"] == uname]
if df.empty:
print("Invalid Username given")
return False
else:
df = df.loc[df["password"] == pwd]
if df.empty:
print("Invalid Password")
return False
else:
print("Username and Password matched successfully")
return True
def searchBook():
name = input("Enter book title to be searched : ")
bdf = pd.read_csv("books.csv")
df = bdf.loc[bdf["title"] == name]
if df.empty:
print("No book found with given title")
return False
else:
print("Book details are ")
print(df)
return True
def deleteBook():
name = input("Enter book title to be deleted : ")
bdf = pd.read_csv("books.csv")
bdf = bdf.drop(bdf[bdf["title"] == name].index)
bdf.to_csv("books.csv",index = False)
print("Book Deleted Successfully")
def showBooks():
bdf = pd.read_csv("books.csv")
print(bdf)
def addNewMember():
mid = int(input("Enter Member id : "))
name = input("Enter name of the member : ")
phone = input("Enter phone number : ")
email = input("Enter email id : ")
address = input("Enter address : ")
number = 0
mdf = pd.read_csv("members.csv")
n = mdf["Memberid"].count()
mdf.at[n] = [mid, name, phone, email, address, number]
mdf.to_csv("members.csv", index=False)
print("Member added successfully")
def searchMember():
name = input("Enter member name to be searched : ")
mdf = pd.read_csv("members.csv")
df = mdf.loc[mdf["name"] == name]
if df.empty:
print("No member found with given name")
return False
else:
print("Member details are ")
print(df)
return True
def deleteMember():
name = input("Enter member name to be deleted : ")
mdf = pd.read_csv("members.csv")
mdf = mdf.drop(mdf[mdf["name"] == name].index)
mdf.to_csv("members.csv", index=False)
print("Member Deleted Successfully")
def showMembers():
mdf = pd.read_csv("members.csv")
print(mdf)
def issueBook():
bname = input("Enter Book name to be searched : ")
df = pd.read_csv("books.csv")
df = df.loc[df["title"] == bname]
if df.empty:
print("No Book Found in the Library")
return
mname = input("Enter member name to be searched : ")
df = pd.read_csv("members.csv")
df = df.loc[df["Name"] == mname]
if df.empty:
print("No such Member Found")
return
idf = pd.read_csv("issuedbooks.csv")
book_issue = [bname,mname,date.today(),""]
n = idf["book_name"].count()
idf.at[n] = book_issue
idf.to_csv("issuedbooks.csv",index = False)
print("Book Issued Successfully")
df = pd.read_csv("members.csv")
def showIssuedBooks():
idf = pd.read_csv("issuedbooks.csv")
print(idf)
def returnBook():
bname = input("Enter Book to be returned : ")
mname = input("Enter Member who has the book : ")
idf = pd.read_csv("issuedbooks.csv")
idf = idf.loc[idf["book_name"] == bname]
if idf.empty:
print("The book is not issued in records")
else:
idf = idf.loc[idf["member_name"] == mname]
if idf.empty:
print("The book is not issued to the member")
else:
print("Book can be returned")
ans = input("Are you sure you want to return the book : ")
if ans.lower() == "yes":
idf = pd.read_csv("issuedbooks.csv")
idf = idf.drop(idf[idf["book_name"] == bname].index)
idf.to_csv("issuedbooks.csv", index=False)
print("Book Returned Successfully")
else:
print("Return operation cancelled")
def showchart():
print("Press 1 - Books and their Cost")
print("Press 2 - Fine Paid by Members")
print("Press 3 - Frequently Issued Books")
print("Press 4 - No. of Books Issued per week")
ch = int(input("Enter your choice : "))
if ch == 1:
bdf = pd.read_csv("books.csv")
df = bdf[["title","cost"]]
bdf.plot(kind='bar')
#print(bdf)
def showMenu():
print("-----------------------------")
print(" ABC LIBRARY MGT ")
print("-----------------------------")
print("Press 1 - Add a New Book")
print("Press 2 - Search for a Book")
print("Press 3 - Delete a Book")
print("Press 4 - Show All Books")
print("Press 5 - Add a New Member")
print("Press 6 - Search for a Member")
print("Press 7 - Delete a Member")
print("Press 8 - Show All Members")
print("Press 9 - Issue a Book")
print("Press 10 - Return a Book")
print("Press 11 - Show All Issued Books")
print("Press 12 - To view Charts")
print("Press 13 - To Exit")
choice = int(input("Enter your choice : "))
return choice
if login():
while True:
ch = showMenu()
if ch == 1:
addNewBook()
elif ch == 2:
searchBook()
elif ch == 3:
deleteBook()
elif ch == 4:
showBooks()
elif ch == 5:
addNewMember()
elif ch == 6:
searchMember()
elif ch == 7:
deleteMember()
elif ch == 8:
showMembers()
elif ch == 9:
issueBook()
elif ch == 10:
returnBook()
elif ch == 11:
showIssuedBooks()
elif ch == 12:
showchart()
elif ch == 13:
break
else:
print("Invalid Option Selected")