1
- #===================================||
2
- # School Library Management Project ||
3
- #===================================||
1
+ #============================================================================================================================================================||
2
+ # School Library Management Project ||
3
+ #============================================================================================================================================================||
4
+
5
+ #Importing Modules
4
6
5
7
import time
6
8
import os
@@ -10,28 +12,28 @@ def database():
10
12
print ("============================================================================" )
11
13
print ("\t \t \t Database Menu" )
12
14
print ("============================================================================" )
13
- print ("Welcome User. Choose the Desired Action." )
14
- cursor .execute ("show databases;" )
15
- databases = cursor .fetchall ()
16
- dbs = {}
15
+ print ("Welcome User. Choose the Desired Action." ) #Menu
16
+ cursor .execute ("show databases;" ) #Executed SQL Query to get DataBases Name
17
+ databases = cursor .fetchall () #Stored all the DataBases Names in variable
18
+ dbs = {} #Created dictionary
17
19
n = 1
18
- for i in databases :
20
+ for i in databases : #Looping to print the databases names
19
21
dbs [n ] = i [0 ]
20
22
print (str (n ) + ". " + i [0 ])
21
23
n += 1
22
- dbs [n ] = "Create A New DataBase"
23
- dbs [n + 1 ] = "Exit From The Connection"
24
+ dbs [n ] = "Create A New DataBase" #Creating 2 more options and
25
+ dbs [n + 1 ] = "Exit From The Connection" #assigning these in dictionary dbs
24
26
print ("****************************************************************************" )
25
27
print (str (n ) + ". " + "Create A New DataBase" )
26
28
print (str (n + 1 ) + ". " + "Exit From The Connection" )
27
29
decision = 0
28
30
while decision not in range (1 , n + 1 ) :
29
- decision = int (input ("Enter your choice => " ))
30
- if decision in range (1 , n ) :
31
+ decision = int (input ("Enter your choice => " )) #If decision is not any of the specified options, input again
32
+ if decision in range (1 , n ) :
31
33
query = "USE " + dbs [decision ]
32
- cursor .execute (query )
34
+ cursor .execute (query ) #Selected DB will be used
33
35
os .system ("cls" )
34
- tables (dbs [decision ])
36
+ tables (dbs [decision ]) #Selected DB's Tables Menu will be opened
35
37
elif decision == n :
36
38
new_db_name = input ("Enter The New DataBase Name(A-Z,a-z,0-9,_) => " )
37
39
if new_db_name == "" :
@@ -40,7 +42,7 @@ def database():
40
42
dec = input ("Are you sure you want to Create This DataBase?(y/n) => " )
41
43
if dec == "y" :
42
44
query = "create database " + new_db_name
43
- cursor .execute (query )
45
+ cursor .execute (query ) #Creating new DB
44
46
cnx .commit ()
45
47
print ("Successfully created '" + new_db_name + "' DataBase..." )
46
48
input ("Press Enter to go to DataBase Menu..." )
@@ -51,7 +53,7 @@ def database():
51
53
exit_decision = input ("Are you sure you want to Exit?(y/n) => " )
52
54
if exit_decision == "y" :
53
55
cnx .close ()
54
- print ("See ya later." )
56
+ print ("See ya later." ) #Exit
55
57
time .sleep (3 )
56
58
quit ()
57
59
else :
@@ -68,17 +70,17 @@ def tables(db) :
68
70
print ("============================================================================" )
69
71
cursor .execute ("show tables" )
70
72
tables = cursor .fetchall ()
71
- n = 1
73
+ n = 1 #Printing all Tables Names
72
74
for i in tables :
73
75
print (str (n ) + ". " + i [0 ])
74
76
n += 1
75
77
print ("****************************************************************************" )
76
78
print ("This Python Program Will Now Use These 3 Tables in this DataBase:" )
77
79
print ("$. School_Students $. Library_Books $. Issued_Books" )
78
- print ("If these tables exist already with the Specified Columns in ReadMe, use" )
79
- print ("them directly. Otherwise Create these Tables." )
80
+ print ("If these tables exist already with the Specified Columns in ReadMe, use" ) #Before creating these 3 tables, check the Table Structure
81
+ print ("them directly. Otherwise Create these Tables." ) #from the ReadMe
80
82
decision = input ("Do you want to Create these Tables here?(y/n) => " )
81
- if decision == "y" :
83
+ if decision == "y" : #Creating Tables via SQL Query
82
84
cursor .execute ("""CREATE TABLE IF NOT EXISTS issued_books (
83
85
Accession_No int NOT NULL PRIMARY KEY CHECK (Accession_No > 0),
84
86
Book_Name varchar(200) NOT NULL,
@@ -100,7 +102,7 @@ def tables(db) :
100
102
)""" )
101
103
cnx .commit ()
102
104
print ("Tables Created Successfully..." )
103
- decision = input ("Do you want to Use these Tables here?(y/n) => " )
105
+ decision = input ("Do you want to Use these Tables here?(y/n) => " ) #Use the Tables in Menu
104
106
if decision == "y" :
105
107
os .system ("cls" )
106
108
menu ()
@@ -127,7 +129,7 @@ def menu() :
127
129
if decision == "1" :
128
130
os .system ("cls" )
129
131
library ()
130
- elif decision == "2" :
132
+ elif decision == "2" : #Library and School Menus can be accessed
131
133
os .system ("cls" )
132
134
school ()
133
135
elif decision == "3" :
@@ -174,7 +176,7 @@ def library() :
174
176
os .system ("cls" )
175
177
modify_book ()
176
178
elif decision == "5" :
177
- os .system ("cls" )
179
+ os .system ("cls" ) #Library Menu and its Functions
178
180
issue_book ()
179
181
elif decision == "6" :
180
182
os .system ("cls" )
@@ -209,7 +211,7 @@ def school() :
209
211
os .system ("cls" )
210
212
show_students ()
211
213
elif decision == "2" :
212
- os .system ("cls" )
214
+ os .system ("cls" ) #School Menu and its Functions
213
215
add_student ()
214
216
elif decision == "3" :
215
217
os .system ("cls" )
@@ -230,10 +232,10 @@ def show_books() :
230
232
data = cursor .fetchall ()
231
233
n = 1
232
234
for row in data :
233
- print (str (n ) + ". Accesion No. : {0}\n Book Name : {1}\n Author : {2}\n Price : {3}" .format (row [0 ], row [1 ], row [2 ], row [3 ]))
234
- n += 1
235
- print ("****************************************************************************" )
236
- input ("Press Enter to go back to the Library..." )
235
+ print (str (n ) + ". Accesion No. : {0}\n Book Name : {1}\n Author : {2}\n Price : {3}" .format (row [0 ], row [1 ], row [2 ], row [3 ])) #Printing, Accession
236
+ n += 1 #No., Book Name,
237
+ print ("****************************************************************************" ) #Author, Price of
238
+ input ("Press Enter to go back to the Library..." ) #each book
237
239
os .system ("cls" )
238
240
library ()
239
241
@@ -245,8 +247,8 @@ def add_book() :
245
247
print ("============================================================================" )
246
248
cursor .execute ("select accession_no, book_name from library_books;" )
247
249
data = cursor .fetchall ()
248
- a = [ ]
249
- b = [ ]
250
+ a = [ ] #List to store all accession no
251
+ b = [ ] #List to store all book name
250
252
for i in data :
251
253
a .append (i [0 ])
252
254
b .append (i [1 ])
@@ -303,7 +305,7 @@ def delete_book() :
303
305
print ("============================================================================" )
304
306
cursor .execute ("select accession_no from library_books;" )
305
307
data = cursor .fetchall ()
306
- a = [ ]
308
+ a = [ ] #List to store all accession no. from library_books
307
309
for i in data :
308
310
a .append (i [0 ])
309
311
acc_no = int (input ("Enter the Accession No. => " ))
@@ -316,7 +318,7 @@ def delete_book() :
316
318
query = "select book_name, author, price_in_rs from library_books where accession_no = (%s)"
317
319
cursor .execute (query , data )
318
320
data = cursor .fetchall ()
319
- b = [ ]
321
+ b = [ ] #List to store all other info of book to be deleted
320
322
for i in data :
321
323
b .append (i [0 ])
322
324
b .append (i [1 ])
@@ -328,7 +330,7 @@ def delete_book() :
328
330
if decision == "y" :
329
331
cursor .execute ("select accession_no from issued_books;" )
330
332
data = cursor .fetchall ()
331
- c = [ ]
333
+ c = [ ] #List to store all accession no from issued_books
332
334
for i in data :
333
335
c .append (i [0 ])
334
336
if acc_no in c :
@@ -761,20 +763,19 @@ def modify_student() :
761
763
school ()
762
764
763
765
764
- username = input ("Enter the User Name for MySQL Conenction => " )
766
+ username = input ("Enter the User Name for MySQL Conenction => " ) #Authorization to connect to the MySQL in local machine
765
767
password = input ("Enter the Password to access the MySQL Connection => " )
766
768
os .system ("cls" )
767
769
try :
768
- cnx = mysql .connector .connect (host = "127.0.0.1" , user = username , passwd = password )
770
+ cnx = mysql .connector .connect (host = "127.0.0.1" , user = username , passwd = password ) #Trying to connect to MySQL and creating Connection Object
769
771
except :
770
- print ("Incorrect Password ." )
772
+ print ("Incorrect Login Details ." ) #When fails authorization
771
773
input ("Press Enter to Close the Program..." )
772
774
exit
773
775
if cnx :
774
776
print (cnx )
775
777
print ("Successfully Connected..." )
776
- cursor = cnx .cursor ()
778
+ cursor = cnx .cursor () #Created Cursor for Connection Object
777
779
input ("Press Enter to Access the Database Menu..." )
778
780
os .system ("cls" )
779
781
database ()
780
-
0 commit comments