Skip to content

Commit c933227

Browse files
authored
Update project.py
1 parent f1c6f91 commit c933227

1 file changed

Lines changed: 97 additions & 25 deletions

File tree

project.py

Lines changed: 97 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,92 @@
1+
# This project is created by Aswanth R
2+
# For any reference or corrections please post and comment of out respo
3+
# Here is link https://github.com/NodeX-AR/CS-Project/
4+
# For better function of script please close with the code of project rather than manual closing !
15
import mysql.connector as sqlcon
6+
7+
#connection
28
db=sqlcon.connect(
39
host='localhost',
410
user='root',
5-
password='<password>', # Change this
6-
database='library' # Change this
11+
password='Aswanth@2009', # Change this
12+
database='mysql'
713
)
8-
9-
cursor=db.cursor()
1014

15+
#checking connection
16+
if db.is_connected() == False:
17+
print("================== E R R O R =====================")
18+
print("Please check your connection of MySQL with Python!")
19+
print("To check your connection please run the connection")
20+
print("test script given in the same respo and crosscheck")
21+
print("error code and fix in our respo or google.")
22+
print("GitHub Respo Link =>")
23+
print("https://github.com/Nodex-AR/CS-Project")
24+
25+
#checking configs for project
26+
cursor=db.cursor()
27+
cursor.execute("show databases")
28+
t_db=cursor.fetchall()
29+
configdb = ('library',)
30+
if configdb in t_db:
31+
print("All Configs already set !")
32+
cursor.execute("USE library")
33+
34+
#doing configs for project
35+
else:
36+
print("Please wait till we make changes !")
37+
cursor.execute("CREATE DATABASE library")
38+
print("+---------------------------------------------------------+")
39+
print("| SETIING CONFIGS.......... |")
40+
print("+---------------------------------------------------------+")
41+
print("| [0000000 ][ 20 % ] |")
42+
cursor.execute("USE library")
43+
print("| [00000000000000000 ][ 40 % ] |")
44+
db.commit()
45+
print("| [0000000000000000000000000 ][ 60 % ] |")
46+
cursor.execute("CREATE table list ( student_name Varchar(50) , book Varchar(100) , status Varchar(30)) ")
47+
print("| [0000000000000000000000000000000 ][ 80 % ] |")
48+
db.commit()
49+
print("| [000000000000000000000000000000000000000000000][ 100% ] |")
50+
51+
#registry section
1152
def registry():
12-
cursor.execute("Select * from list")
13-
data=cursor.fetchall()
14-
print("|Index No | Name | Book | Status |")
53+
cursor.execute("SELECT * FROM `list`")
54+
total_students = cursor.fetchall()
55+
56+
cursor.execute("SELECT * FROM `list` WHERE status = 'Book Issued'")
57+
books_out = cursor.fetchall()
58+
print("| Library Statistics |")
1559
print("+---------------------------------------------------------+")
16-
for i in data:
17-
print(i)
18-
60+
print("| Total Registered Students: ",len(total_students))
61+
print("| Books Currently Issued: ",len(books_out))
62+
63+
#section to add a new student
1964
def new():
2065
n=input("Enter the name of new student:")
2166
query = "INSERT INTO `list` (student_name) VALUES (%s)"
67+
2268
cursor.execute(query,(n,))
2369
db.commit()
2470
print("Student",n,"is sucessfully added.")
25-
71+
72+
#section to return book
2673
def breturn():
2774
n=input("Enter the name of new student:")
2875
query = "UPDATE `list` SET status = 'Book Returned', book = NULL WHERE student_name = %s"
2976
cursor.execute(query,(n,))
3077
db.commit()
3178
print("Student",n," has retured the book. Status Updated !")
32-
79+
80+
#section to issue a book
3381
def issue():
3482
n=input("Enter the name of new student:")
35-
query = "SELECT status FROM `list` WHERE student_name = %s"
36-
cursor.execute(query,(n,))
83+
cursor.execute("SELECT status FROM `list` WHERE student_name = '%s'"%(n))
3784
result = cursor.fetchone()
3885
if result is None:
3986
print("Student not found.")
4087
return
4188

89+
4290
elif result[0] == "Book Issued":
4391
print("The student",n,"has already been issued a book.")
4492
return
@@ -49,6 +97,8 @@ def issue():
4997
db.commit()
5098
print("Book",b,"issued to",n,"successfully!")
5199

100+
101+
#section to check the status of a student
52102
def status():
53103
n=input("Enter the name of new student:")
54104
query = "SELECT status,book FROM `list` WHERE student_name = %s"
@@ -68,24 +118,40 @@ def status():
68118
else:
69119
print("The student",n,"has never taken a book.")
70120

121+
#master reset section !
122+
def reset():
123+
ans = input("|Are You Sure About reset [Y/N] :").lower()
124+
print("+---------------------------------------------------------+")
125+
if ans == 'y':
126+
cursor.execute("Drop database library")
127+
check = cursor.fetchall()
128+
print("|Reset Protocol Executed Successfully. Now Please restart!|")
129+
db.commit()
130+
print("+---------------------------------------------------------+")
131+
else:
132+
print("|Exiting Reset Protocol. Please restart this program ! |")
133+
print("+---------------------------------------------------------+")
134+
135+
#main workflow
71136
def main():
72137
print("+---------------------------------------------------------+")
73138
print("| LIBRARY MANAGEMENT SYSTEM |")
74139
while True:
75140
print("+---------------------------------------------------------+")
76141
print("|Options : |")
77142
print("+---------------------------------------------------------+")
78-
print("|1.Close the system. |")
79-
print("|2.Show the entire registry. |")
143+
print("|1.Issue of book. |")
144+
print("|2.Show the registry. |")
80145
print("|3.Add new student. |")
81146
print("|4.Return of book. |")
82-
print("|5.Issue of book. |")
83-
print("|6.Check the status of a student. |")
147+
print("|5.Check the status of a student. |")
148+
print("|6.Close the system. |")
149+
print("|7.Master Reset. |")
84150
print("+---------------------------------------------------------+")
85151
opt=input("|Enter the option index number :")
86152
print("+---------------------------------------------------------+")
87153
if opt == "1" :
88-
break
154+
issue()
89155

90156
elif opt == "2":
91157
registry()
@@ -97,17 +163,23 @@ def main():
97163
breturn()
98164

99165
elif opt == "5":
100-
issue()
101-
102-
elif opt == "6":
103166
status()
104-
167+
168+
elif opt == "6":
169+
break
170+
171+
elif opt == "7":
172+
reset()
173+
break
105174
else:
106175
print("Please enter a valid option")
107176
continue
108-
print(" Thank You using our program |")
177+
print("| Thank You using our program :) |")
109178
print("+---------------------------------------------------------+")
110179
db.close()
111-
180+
181+
#start section
112182
if __name__ == "__main__":
113183
main()
184+
185+
#Please don't do any change without knowing what your are doing !

0 commit comments

Comments
 (0)