-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary management system.py
165 lines (158 loc) · 7.08 KB
/
library management system.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
from time import sleep
import datetime
import os
def create_password():
print("\n---------------------------------------------------------------\n")
print("\n-------------------- Create New Password --------------------\n")
while(1):
n=input("\n\nEnter the Password: ")
m=input("\nConfirm The Password: ")
if(n==m):
f=open("pass.txt","w")
f.write(""+m+"")
f.close()
break
else: print("\n\nPassword Didn't Match Try Again")
print("\n---------------------- Password Created -----------------------\n\n")
def password_check(string):
f=open("pass.txt","r")
st=[]
for l in f:
st.append(l)
ne="".join(st)
f.close()
if(ne==string): return 1
else: return 0
f=open("pass.txt","a")
f.close()
print("\n\n---------------------------------------------------------------\n")
print("----------------- Library Management System -----------------\n\n")
if (os.path.getsize('pass.txt') == 0):
print("\n\n - Password is Not Set -\n - Set a Strong Password For Your System -\n - Remember Your Password - \n - Password Can be Set Once Only\n\n")
create_password()
print("\n---------------------------------------------------------------\n")
print(" - You Need to Enter Password to Continue")
print(" - You Have only 3 chances to Enter Password")
ti=1
o=25
over=1
while(over):
string=input("\n - Enter Password: ")
a=password_check(string)
if(a):
print("\n\n---------------------------------------------------------------\n")
print("\n------------------- Welcome to the System -------------------\n\n")
while(1):
print("\n\n---------------------------------------------------------------")
a=int(input("\n1: Add a Book\n2: Delete a Book\n3: Display All Books\n4: Book Borrow Request\n5: Book Return Request\n6: Enter '0' to Exit\n\nEnter Your Choice: "))
if(a==0):
print("\n\n------------------------------------------------------\n")
print("-------------Thanks For Using Our Service-------------\n")
over=0
break
elif(a==1):
print("\n\n---------------------------------------------------------------\n")
print("------------------- Enter the Book's Data -------------------\n")
f=open("libdata.txt","a")
name=input("\n - Enter the Name of the Book: ")
author=input("\n - Enter the Name of the Author: ")
book_id=input("\n - Enter the Book ID: ")
status=input("\n - Status(Avail/Issued): ")
f.writelines("\n"+name.capitalize()+" "+author.capitalize()+" "+book_id+" "+status.capitalize())
f.close()
elif(a==2):
print("\n\n---------------------------------------------------------------\n")
print("------------------- Enter the Book's Data -------------------\n")
name=input("\n - Enter Book Name: ")
found=0
f=open("libdata.txt","r")
g=open("new.txt","w")
data=f.readlines()
f.close()
for i in data:
j=i.split()
if((name.capitalize()) in j):
found=1
continue
else:
g.writelines(""+i)
g.close()
f=open("libdata.txt","w")
g=open("new.txt","r")
for i in g:
f.write(""+i)
if(found): print("\n -- Book Deleted -- \n")
else: print("\n -- Book Not Found -- \n")
elif(a==3):
print("\n\n---------------------------------------------------------------\n")
print("-------------------- All Book's Details --------------------\n\n")
f=open("libdata.txt","r")
print("\n Name\tAuthor\tBook-Id\tStatus\n")
data=f.readlines()
for i in range(1,len(data)):
print(i,": ",data[i],end="\n")
f.close()
print("\n\n---------------------------------------------------------------\n")
elif(a==4):
print("\n\n---------------------------------------------------------------\n")
print("------------------- Book Borrow Request -------------------\n")
name=input("\n - Enter Book Name: ")
found=0
f=open("libdata.txt","r")
g=open("new.txt","w")
data=f.readlines()
f.close()
for i in data:
j=i.split()
if((name.capitalize()) in j):
found=1
j[-1]="Issued"
g.writelines(" ".join(j))
else:
g.writelines(""+i)
g.close()
f=open("libdata.txt","w")
g=open("new.txt","r")
for i in g:
f.write(""+i)
if(found): print("\n -- Book Updated -- \n")
else: print("\n -- Book Not Found -- \n")
elif(a==5):
print("\n\n---------------------------------------------------------------\n")
print("------------------- Book Return Request -------------------\n")
name=input("\n - Enter Book Name: ")
found=0
f=open("libdata.txt","r")
g=open("new.txt","w")
data=f.readlines()
f.close()
for i in data:
j=i.split()
if((name.capitalize()) in j):
found=1
j[-1]="Avail"
g.writelines(" ".join(j))
else:
g.write(""+i)
g.close()
f=open("libdata.txt","w")
g=open("new.txt","r")
for i in g:
f.write(""+i)
if(found): print("\n -- Book Updated -- \n")
else: print("\n -- Book Not Found -- \n")
else:
print("\n - Wrong Choice Try Again - \n")
elif(ti<3):
print("\n\n---------------------------------------------------------------\n")
print("\n - Incorrect Password Try Again - \n - You Have only",3-ti,"Attempts -\n\n")
ti+=1
elif(o>125):
print("\n\n---------------------------------------------------------------")
print("\n - Too Many Attempts - \n - GoodBye - \n\n")
else:
print("\n\n---------------------------------------------------------------\n")
print("\n - You Have Used all 3 Chance's\n - Wait for",o,"Secounds\n")
ti=1
sleep(o)
o+=25