Repository navigation
Expand file tree
/
Copy pathlibManager.py.py
More file actions
570 lines (449 loc) · 15.2 KB
/
Copy pathlibManager.py.py
File metadata and controls
570 lines (449 loc) · 15.2 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
from random import randint
import mysql.connector as mysc
def manage(csr):
'''Management Controls'''
print()
print('MANAGEMENT CONTROLS:')
print()
while True:
print('1. View All Books')
print('2. Add Book')
print('3. Delete Book')
print('4. Choose Language')
print('5. Choose Genre')
print('6. Book Search')
print('7. Back')
minp=input("Enter required option:")
print()
print('*****************************')
'''Each option calls the necessary function'''
if minp=='1':
viewall(csr)
elif minp=='2':
add(csr)
elif minp=='3':
delt(csr)
elif minp == '4':
lang(csr)
elif minp == '5':
gen(csr)
elif minp == '6':
src(csr)
elif minp == '7':
break
else:
print()
print('Enter a Valid Choice!')
print()
print('*****************************')
print()
return
def read(csr):
'''Reader Controls'''
print('How can I help?')
while True:
print('1. View all Books')
print('2. Choose Language')
print('3. Choose Genre')
print('4. Book Search')
print('5. Retrive Book')
print('6. Return Book')
print('7. Back')
rinp=input("Enter required option:")
print()
print('*****************************')
'''Each option calls the necessary function'''
if rinp == '1':
viewall(csr)
elif rinp=='2':
lang(csr)
elif rinp=='3':
gen(csr)
elif rinp=='4':
src(csr)
elif rinp=='5':
retv(csr)
elif rinp=='6':
retn(csr)
elif rinp=='7':
break
else:
print('Enter a Valid Choice!')
print()
print('*****************************')
print()
return
def viewall(csr):
'''Function to View the entire collection of books'''
csr.execute("SELECT * FROM MainShelf ORDER BY Serial")
print()
h=csr.fetchall()
print()
print('Total Books:', csr.rowcount)
print()
if h==[]:
print()
print('****No Books!****')
print()
input('Press Enter to continue...')
print()
print('*****************************')
print()
else:
print()
print('SERIAL | ID | NAME | LANG | GENRE | SHELF | STATUS | READER')
print()
for i in h:
print(i)
print()
input("Press Enter to continue...")
print()
print('*****************************')
print()
return
def add(csr):
'''Function to Add books to all the corresponding tables'''
while True:
print()
print(" BOOK ADDITION")
print()
bname=(input("Enter Book Name:")).capitalize()
blang=(input("Enter Book Language (Eng / Hin / Tam) :")).capitalize()
bgenre=(input("Enter Book Genre (Novel / Ref / Poem ) :")).capitalize()
print()
rid=randint(1,99999) #To Assign a random ID to the books
rshelf=randint(1,25) #To Decide the shelf number randomly
ins="INSERT INTO MainShelf(ID, Name, Language, Genre, Shelf, Status, Reader) VALUES({}, '{}', '{}', '{}', {}, 'Available', '-')".format(rid, bname.capitalize(), blang.capitalize(), bgenre.capitalize(), rshelf)
csr.execute(ins)
cobj.commit()
if blang=='Eng':
ins="INSERT INTO English(ID, Name, Language, Genre, Shelf) VALUES({}, '{}', '{}', '{}', {})".format(rid, bname, blang, bgenre, rshelf)
csr.execute(ins)
cobj.commit()
if blang=='Hin':
ins="INSERT INTO Hindi(ID, Name, Language, Genre, Shelf) VALUES({}, '{}', '{}', '{}', {})".format(rid, bname, blang, bgenre, rshelf)
csr.execute(ins)
cobj.commit()
if blang=='Tam':
ins="INSERT INTO Tamil(ID, Name, Language, Genre, Shelf) VALUES({}, '{}', '{}', '{}', {})".format(rid, bname, blang, bgenre, rshelf)
csr.execute(ins)
cobj.commit()
if bgenre=='Novel':
ins="INSERT INTO Novels(ID, Name, Language, Genre, Shelf) VALUES({}, '{}', '{}', '{}', {})".format(rid, bname, blang, bgenre, rshelf)
csr.execute(ins)
cobj.commit()
if bgenre=='Reference':
ins="INSERT INTO Reference(ID, Name, Language, Genre, Shelf) VALUES({}, '{}', '{}', '{}', {})".format(rid, bname, blang, bgenre, rshelf)
csr.execute(ins)
cobj.commit()
if bgenre=='Poem':
ins="INSERT INTO Poems(ID, Name, Language, Genre, Shelf) VALUES({}, '{}', '{}', '{}', {})".format(rid, bname, blang, bgenre, rshelf)
csr.execute(ins)
cobj.commit()
print()
print('Book Added Successfully!')
print('Unique ID of the Book is:', rid)
print('The book is to be placed at shelf:', rshelf)
print()
b=input('Add another book? [y/n] :')
print()
print()
if b=='n':
print()
print('*****************************')
print()
break
else:
print()
print('*****************************')
print()
continue
return
def delt(csr):
'''Function to delete book from all the corresponding tables'''
print()
print("BOOK DELETION")
while True:
a=input("Enter Book ID to be deleted (Enter 'b' to go back) :")
if a=='b':
print()
print('*****************************')
print()
break
csr.execute('DELETE FROM MainShelf WHERE ID={}'.format(int(a)))
cobj.commit()
'''Deleting from main table deletes from
all other related tables using foreign key relation'''
print()
print('Book Deleted Successfully!')
print()
b=input('Delete another book? [y/n] :')
print()
print()
if b=='n':
print()
print('*****************************')
print()
break
else:
print()
print('*****************************')
print()
continue
return
def lang(csr):
'''Function to Display the required language books'''
a=input('Enter required language ( Eng / Hin / Tam ) :').capitalize()
if a == 'Eng':
csr.execute("SELECT * FROM English ORDER BY Serial")
print()
h=csr.fetchall()
print()
print('Total Books:', csr.rowcount)
print()
if h==[]:
print()
print('****No Books!****')
print()
input('Press Enter to continue...')
print()
print('*****************************')
print()
else:
print()
print('SERIAL | ID | NAME | LANG | GENRE | SHELF')
print()
for i in h:
print(i)
print()
input("Press Enter to continue...")
print()
print('*****************************')
print()
elif a == 'Tam':
csr.execute("SELECT * FROM Tamil ORDER BY Serial")
print()
h=csr.fetchall()
print()
print('Total Books:', csr.rowcount)
print()
if h==[]:
print()
print('****No Books!****')
print()
input('Press Enter to continue...')
print()
print('*****************************')
print()
else:
print()
print('SERIAL | ID | NAME | LANG | GENRE | SHELF')
print()
for i in h:
print(i)
print()
input("Press Enter to continue...")
print()
print('*****************************')
print()
elif a == 'Hin':
csr.execute("SELECT * FROM Hindi ORDER BY Serial")
print()
h=csr.fetchall()
print()
print('Total Books:', csr.rowcount)
print()
if h==[]:
print()
print('****No Books!****')
print()
input('Press Enter to continue...')
print()
print('*****************************')
print()
else:
print()
print('SERIAL | ID | NAME | LANG | GENRE | SHELF')
print()
for i in h:
print(i)
print()
input("Press Enter to continue...")
print()
print('*****************************')
print()
else:
return
return
def gen(csr):
'''Function to Display the required genre books'''
a=input("Enter Book Genre ( Novels / Ref / Poems ) :").capitalize()
if a == 'Novels':
csr.execute("SELECT * FROM Novels ORDER BY Serial")
print()
h=csr.fetchall()
print()
print('Total Books:', csr.rowcount)
print()
if h==[]:
print()
print('****No Books!****')
print()
input('Press Enter to continue...')
print()
print('*****************************')
print()
else:
print()
print('SERIAL | ID | NAME | LANG | GENRE | SHELF')
print()
for i in h:
print(i)
print()
input("Press Enter to continue...")
print()
print('*****************************')
print()
elif a == 'Ref':
csr.execute("SELECT * FROM Reference ORDER BY Serial")
print()
h=csr.fetchall()
print()
print('Total Books:', csr.rowcount)
print()
if h==[]:
print()
print('****No Books!****')
print()
input('Press Enter to continue...')
print()
print('*****************************')
print()
else:
print()
print('SERIAL | ID | NAME | LANG | GENRE | SHELF')
print()
for i in h:
print(i)
print()
input("Press Enter to continue...")
print()
print('*****************************')
print()
elif a == 'Poems':
csr.execute("SELECT * FROM Poems ORDER BY Serial")
print()
h=csr.fetchall()
print()
print('Total Books:', csr.rowcount)
print()
if h==[]:
print()
print('****No Books!****')
print()
input('Press Enter to continue...')
print()
print('*****************************')
print()
else:
print()
print('SERIAL | ID | NAME | LANG | GENRE | SHELF')
print()
for i in h:
print(i)
print()
input("Press Enter to continue...")
print()
print('*****************************')
print()
else:
return
return
def src(csr):
'''Function to Search any required book'''
while True:
c=input("Do you want to search by Book ID (id) or Book Name (name) [Enter 'b' to go back'] : ").capitalize()
if c=='Name':
'''Search by Name'''
a=input("Enter partial or full book name :").capitalize()
csr.execute("SELECT * FROM MainShelf WHERE Name LIKE '{}' ORDER BY Serial".format(a+'%'))
h=csr.fetchall()
print()
print('SERIAL | ID | NAME | LANG | GENRE | SHELF | STATUS | READER')
print()
for i in h:
print(i)
print()
elif c=='Id':
'''Search by ID'''
b=int(input("Enter Book ID:"))
csr.execute("SELECT * FROM MainShelf WHERE ID = {}".format(b))
print()
print()
print('SERIAL | ID | NAME | LANG | GENRE | SHELF | STATUS | READER')
print()
print(csr.fetchone())
print()
else:
break
l=input("Do you want to search another book? [y/n] :")
print()
print()
if l=='n':
print()
print('*****************************')
print()
break
else:
print()
print('*****************************')
print()
continue
return
def retv(csr):
'''Function to update retrival status of any book along with retriver's name'''
a=int(input("Enter ID of book retrived ( View all books to check availability ):"))
b=input("Enter reader name:")
csr.execute("UPDATE MainShelf SET Status = 'In Use', Reader = '{}' WHERE ID = {}".format(b,a))
cobj.commit()
print()
print("Retrival Recorded!")
print()
input('Press Enter to continue...')
print()
print('*****************************')
print()
return
def retn(csr):
'''Function to update book return status for retrived books'''
a=int(input("Enter Book ID to be returned:"))
csr.execute("UPDATE MainShelf SET Status='Available', Reader = '-' WHERE ID = {}".format(a))
cobj.commit()
print()
print("Return Recorded!")
print()
input('Press Enter to continue...')
print()
print('*****************************')
print()
return
"""MAIN"""
cobj=mysc.connect(host='localhost', user='root', passwd='4321', database='LibProject')
csr=cobj.cursor()
print()
print(' SARATHA INTERNATIONAL SCHOOL')
print()
print(' LIBRARY MANAGEMENT')
print()
while True:
ctrl=input(" Do you want to Manage(m), Read(r) or Exit(e):")
print()
'''Each option calls the necessary function'''
if ctrl=='m':
manage(csr)
elif ctrl=='r':
read(csr)
elif ctrl=='e':
break
else:
print('Enter valid choice!')