-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
3455 lines (3293 loc) · 139 KB
/
main.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
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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Starting of the program
#! --------------------------------------------------
#! ---------- Credits
#! --------------------------------------------------
# region credits
# * ---- Made by:
# * ------- Aaloke Eppalapalli
# * ------- Hemanth Tenneti
# * ------- Husain Khorakiwala
# * ---- Source Code:
# * ------- https://github.com/AverageBlank/StudentDatabase
# endregion
#! --------------------------------------------------
#! ---------- Imports
#! --------------------------------------------------
# region Imports
# ? Maths --> For rounding
from math import ceil
# ? Importing OS to get operating system, to run commands in terminal, to block print
from os import name as OsName, system, getcwd, path, makedirs, devnull, popen
# ? Importing string to have a valid name without symbols
from string import ascii_letters, digits, punctuation
# ? Time --> For pausing the program
from time import sleep
# ? Questionary --> To provide choices and autocompletions
import questionary
from questionary import Style
# ? Matplotlib --> for plotting a graph
from matplotlib.pyplot import bar, show, title, xlabel, ylabel
# ? Pandas --> for storing data
import pandas as pd
# ? Rich --> For great terminal user interface
from rich import print
from rich.console import Console
console = Console()
from rich.table import Table
from rich import box
from rich.panel import Panel
from rich.progress import (
BarColumn,
Progress,
TextColumn,
)
from rich.align import Align
# ? Sys --> Prevents printing
import sys
# ? SQLite3 --> For connecting to SQL database
from sqlite3 import connect
# ? Fernet --> For encrypting passwords
from cryptography.fernet import Fernet
# endregion
#! --------------------------------------------------
#! --------------------------------------------------
#! --------------------------------------------------
#! ---------- Functions
#! --------------------------------------------------
# region Functions
# ! Function to prevent printing
def DisablePrint():
sys.stdout = open(devnull, "w")
# ! Function to enable printing
def EnablePrint():
sys.stdout = sys.__stdout__
# ! Function to avoid getting improper section
def IsProperSection(prompt):
while True:
section = questionary.text(prompt, style=minimalStyle).ask()
try:
if len(section) > 2 or len(section) <= 0:
raise ValueError
elif section[0] not in ascii_letters:
raise KeyError
elif len(section) == 2:
if section[1] not in digits or section[1] == " ":
raise TabError
return section.upper()
except ValueError:
print("Length of section cannot have more than 2 or less than 1 character")
except KeyError:
print("Section can only have alphabets as the first character")
except TabError:
print("Section cannot have symbols")
# ! Function to avoid getting improper marks
def IsProperMarks(prompt):
# ? To check for input parameters and returning the desired input.
while True:
try:
# ? Rounds off the marks to the nearest integer value
marks = ceil(float(questionary.text(prompt, style=minimalStyle).ask()))
if 0 > marks or marks > 100:
# ? If marks aren't between 0 or 100, rejects the marks
raise AttributeError
else:
return marks
except AttributeError:
print(f"Marks need to be less than 100 and greater than 0.")
except:
print("Enter valid marks.")
# ! Function to avoid getting an error on an improper name
def IsProperName(name):
# ? Checks for alphanumeric symbols in a name and rejects it if one exists
NumericSymbols = [x for x in digits + punctuation]
while True:
try:
for i in name:
if i in NumericSymbols:
raise ValueError
else:
# ? If no symbols or numbers in a name, return the name
return name
except:
name = (
questionary.text("Enter a valid student's name: ", style=minimalStyle)
.ask()
.title()
)
# ! Function to avoid getting an error on an improper class number
def IsProperClass(classno):
# ? Checks for alphanumeric symbols in a name and rejects it if one exists
AlphabeticalSymbols = [x for x in ascii_letters + punctuation]
while True:
try:
for i in classno:
if i in AlphabeticalSymbols:
raise ValueError
else:
# ? If no symbols or numbers in a name, return the name
return int(classno)
except:
classno = questionary.text(
f"Please enter a valid class number.", style=minimalStyle
).ask()
# ! Function to avoid getting an error on fcore input depending on user's stream
def IsProperFcore(Fcore, Stream):
while True:
try:
# ? If 5th core is not valid, raise a ValueError
if Fcore.lower() not in [
"mathematics",
"math",
"maths",
"psychology",
"psy",
"informatics practices",
"ip",
"physical education",
"pe",
"fine arts",
"fa",
]:
raise ValueError
else:
# ? When chosen stream is valid, rename it to a common name to keep it uniform
if Stream.lower() == "humanities" or Stream.lower() == "mpc":
if Fcore.lower() in ["math", "mathematics", "maths"]:
raise ValueError
if Fcore.lower() == "math" or Fcore.lower() == "maths":
Fcore = "Mathematics"
if Fcore.lower() == "psy":
Fcore = "Psychology"
if Fcore.lower() == "ip":
Fcore = "Informatics Practices"
if Fcore.lower() == "pe":
Fcore = "Physical Education"
if Fcore.lower() == "fa":
Fcore = "Fine Arts"
return Fcore
except:
# ? If checks fail, ask for an input again
Fcore = questionary.select(
"Choose a valid 5th Core: ",
choices=[
"Mathematics",
"Informatics Practices",
"Psychology",
"Physical Education",
"Fine Arts",
],
style=minimalStyle,
instruction="\n",
).ask()
# ! Function to avoid getting an error on choosing a 3rd language
def IsProperLang3(Lang3Name, Lang2Name):
while True:
try:
# ? Checks for improper languages given and raises error
if Lang3Name.lower() not in [
"hindi",
"h",
"telugu",
"t",
"french",
"f",
"sanskrit",
"s",
]:
raise ValueError
else:
# ? Refactors given input of a language into a uniform input for all
if Lang3Name.lower() == "h":
Lang3Name = "Hindi"
if Lang3Name.lower() == "t":
Lang3Name = "Telugu"
if Lang3Name.lower() == "f":
Lang3Name = "French"
if Lang3Name.lower() == "s":
Lang3Name = "Sanskrit"
if Lang2Name == Lang3Name:
raise ValueError
return Lang3Name
except:
Lang3Name = (
questionary.select(
"Choose a valid 3rd language: ",
choices=["Hindi", "Telugu", "French", "Sanskrit"],
style=minimalStyle,
instruction="\n",
)
.ask()
.title()
)
# ! Function to avoid getting an error on a wrong roll number input
def IsProperRollNum(RollNum):
# ? Checks for an incorrect roll number between 0 and 60
while True:
try:
if RollNum > 60 or RollNum <= 0:
raise ValueError
else:
return RollNum
except:
RollNum = abs(
int(
questionary.text(
"Enter a valid roll number: ", style=minimalStyle
).ask()
)
)
# ! Function to clear the terminal screen depending on OS type
def ClearScreen():
# ? Checks for OS type and then clears the terminal
sleep(0.2)
# ? Posix here is Macintosh and Linux, nt is Windows.
system("clear" if OsName == "posix" else "cls")
console.print(
Panel.fit("[bold italic #77DDD4]Student Management System", padding=(0, 22))
)
print()
# ! Function to display a status bar
def StatBar(time: float, desc: str):
progress_bar = Progress(
TextColumn(f"{desc} "),
BarColumn(),
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
)
with progress_bar as p:
for i in p.track(range(100), description=desc):
sleep(time / 100)
sleep(0.5)
# endregion
#! --------------------------------------------------
#! --------------------------------------------------
#! --------------------------------------------------
#! ---------- Main Program
#! --------------------------------------------------
# region Main Program
########! Connecting to the server !########
# ! <-- Connecting to the server and creating necessary tables -->
def Backend():
# ! <-- Globals for making life easier -->
global db, con, cur, console, minimalStyle, fernet
# ! <-- Encrypting password so people who think they're smart can't access it -->
try:
if OsName == "nt":
chk = popen("cd %userprofile% && dir").read()
CWD = popen("cd %userprofile% && chdir").read()
CWD = CWD[:-1] + "\\"
if "forpsd" in chk:
with open(CWD + "forpsd", "rb") as keyFile:
key = keyFile.read()
else:
raise ValueError
elif OsName == "posix":
chk = popen("ls ~").read()
CWD = popen("cd ~ && pwd").read()
if "forpsd" in chk:
with open(CWD[:-1] + "/forpsd", "rb") as keyFile:
key = keyFile.read()
else:
raise ValueError
except:
key = Fernet.generate_key()
with open(CWD[:-1] + "/forpsd", "wb") as keyFile:
keyFile.write(key)
fernet = Fernet(key.decode("utf-8"))
# ! <-- Colors -->
minimalStyle = Style(
[
("answer", "fg:#FFFFFF italic"), # ? White
("question", "fg:#FFFFFF bold"), # ? White
("pointer", "fg:#00FFFF bold"), # ? Cyan
("highlighted", "fg:#FFFFFF"), # ? White
("selected", "fg:#A9A9A9"), # ? Grey
("qmark", "fg:#77DD77"), # ? Green
]
)
# ? Connecting to the MySQL database
con = connect("StudentDatabase.db")
cur = con.cursor()
db = "studentdatabase"
# ! <-- Creating basic Databases and Tables -->
cur.execute(
f"create table if not exists teacherDB(user varchar(64) primary key, pass varchar(100))"
)
cur.execute(
f"create table if not exists allstudents(AdmNum int primary key, name varchar(100), class int, section varchar(10))"
)
# ! <-- Creating class tables for MySQL -->
# ** <-- CAT IS CATEGORY -->
# ? Grade 1
cur.execute(
f"""CREATE TABLE if not exists catone(AdmNum int primary key, Name VARCHAR(50), Class INT, Section varchar(10), RollNumber INT, Lang2Name VARCHAR(50), English INT, Mathematics INT, Science INT, SocialSciences INT, Lang2 INT, Total INT, Average FLOAT)"""
)
# ? Grade 2 - Grade 4
cur.execute(
f"""CREATE TABLE if not exists cattwo(AdmNum int primary key, Name VARCHAR(50), Class INT, Section varchar(10), RollNumber INT, Lang2Name VARCHAR(50), English INT, Mathematics INT, Science INT, SocialSciences INT, Lang2 INT, Computers INT, Total INT, Average FLOAT)"""
)
# ? Grade 5 - Grade 8
cur.execute(
f"""CREATE TABLE if not exists catthree(AdmNum int primary key, Name VARCHAR(50), Class INT, Section varchar(10), RollNumber INT, Lang2Name VARCHAR(50), Lang3Name VARCHAR(50), English INT, Mathematics INT, Science INT, SocialSciences INT, Lang2 INT, Lang3 INT, Computers INT, Total INT, Average FLOAT)"""
)
# ? Grade 9-10
cur.execute(
f"""CREATE TABLE if not exists catfour(AdmNum int primary key, Name VARCHAR(50), Class INT, Section varchar(10), RollNumber INT, Lang2Name VARCHAR(50), English INT, Mathematics INT, Science INT, SocialSciences INT, Lang2 INT, Total INT, Average FLOAT)"""
)
# ? MPC
cur.execute(
f"""CREATE TABLE if not exists catfive(AdmNum int primary key, Name VARCHAR(50), Class INT, Section varchar(10), RollNumber INT, FcoreName VARCHAR(50), English INT, Mathematics INT, Physics INT, Chemistry INT, Fcore INT, Total INT, Average FLOAT)"""
)
# ? BiPC
cur.execute(
f"""CREATE TABLE if not exists catsix(AdmNum int primary key, Name VARCHAR(50), Class INT, Section varchar(10), RollNumber INT, FcoreName VARCHAR(50), English INT, Biology INT, Physics INT, Chemistry INT, Fcore INT, Total INT, Average FLOAT)"""
)
# ? Commerce
cur.execute(
f"""CREATE TABLE if not exists catseven(AdmNum int primary key, Name VARCHAR(50), Class INT, Section varchar(10), RollNumber INT, FcoreName VARCHAR(50), English INT, Accounts INT, BusinessStudies INT, Economics INT, Fcore INT, Total INT, Average FLOAT)"""
)
# ? Humanities
cur.execute(
f"""CREATE TABLE if not exists cateight(AdmNum int primary key, Name VARCHAR(50), Class INT, Section varchar(10), RollNumber INT, FcoreName VARCHAR(50), English INT, History INT, PoliticalSciences INT, Economics INT, Fcore INT, Total INT, Average FLOAT)"""
)
con.commit()
########! Related to Login !########
# ! <-- If register is called -->
def RegisterUser(User=None, Pass=None):
# ? Clearing the screen
ClearScreen()
if User == None:
while True:
# ? Taking username incase not provided
User = questionary.text("Enter the username: ", style=minimalStyle).ask()
for i in User:
if i in punctuation or i in digits:
print("Cannot contain symbols or digits")
continue
if len(User) < 3:
print("Length of the username must be greater than 3")
continue
if " " in User:
print("Username cannot contain spaces")
continue
break
if Pass == None:
while True:
# ? Taking password incase not provided
Pass = questionary.password(
"Enter your password: ", style=minimalStyle
).ask()
if len(Pass) < 8:
print("Length of the password must be greater than 8")
continue
Pass = fernet.encrypt(f"{Pass}".encode())
break
# ? Running the signup system
cur.execute(f'select * from teacherDB where user="{User}"')
userFetch = cur.fetchall()
if len(userFetch) == 0:
cur.execute(rf'insert into teacherDB values("{User}", "{Pass}")')
con.commit()
print("Successfully created user.")
input("Press enter to continue ")
else:
ClearScreen()
print("This user already exists!")
LoginUser(
User,
questionary.password(
"Enter the password for the user: ", style=minimalStyle
).ask(),
)
# ! <-- If Login is called -->
def LoginUser(User=None, Pass=None):
# ? Number of wrong passwords entered
NPass = 0
# ? Clearing the screen
ClearScreen()
# ? Taking username incase not provided
if User == None:
while True:
User = questionary.text("Enter the username: ", style=minimalStyle).ask()
for i in User:
if i in punctuation or i in digits:
print("Cannot contain symbols or digits")
break
else:
break
# ? Taking password incase not provided
if Pass == None:
Pass = questionary.password("Enter your password: ", style=minimalStyle).ask()
# ? Running the login system
cur.execute(f'select * from teacherDB where user="{User}"')
userFetch = cur.fetchall()
if len(userFetch) == 0:
ClearScreen()
print("Username doesn't exist!")
register = questionary.confirm(
"Would you like to create a new user? ", style=minimalStyle
).ask()
if register == True:
RegisterUser()
else:
ClearScreen()
print("Exiting Program")
exit()
else:
while True:
userFetchPass = userFetch[0][1][2:-1]
decPass = fernet.decrypt(userFetchPass).decode("utf-8")
if decPass == rf"{Pass}":
ClearScreen()
print("Successful login!")
Align.center(
StatBar(2, desc="[cyan]Loading Student Database"), vertical="middle"
)
break
else:
NPass += 1
ClearScreen()
if NPass == 3:
print("Wrong password entered too many times.")
exit()
else:
print("Wrong Password, please try again.")
Pass = questionary.password(
"Enter your password: ", style=minimalStyle
).ask()
continue
########! Related to student info !########
# ! <-- Adding students -->
def AddStudent():
# ? Clearing Screen
ClearScreen()
# ? Name
Name = IsProperName(
questionary.text("Enter student's name: ", style=minimalStyle).ask()
).title()
# ? Admission Number
while True:
try:
AdmNum = abs(
int(
questionary.text(
f"Enter {Name}'s admission number: ", style=minimalStyle
).ask()
)
)
if AdmNum == 0:
raise ValueError
break
except:
print("Please enter a valid admission number.")
while True:
cur.execute(f"select name from allstudents where AdmNum={AdmNum}")
admNumFetch = cur.fetchall()
try:
if len(admNumFetch) == 0:
ClearScreen()
break
else:
raise ValueError
except:
print("This admission number already exists")
AdmNum = abs(
int(
questionary.text(
"Enter a valid admission number: ", style=minimalStyle
)
)
).ask()
# ? Asking for class
while True:
Class = IsProperClass(
questionary.text(f"Enter {Name}'s class: ", style=minimalStyle).ask()
)
# ! Categorizing by classes
if 1 <= Class <= 3:
# ? Asking for 2nd language name without french
Lang2Name = questionary.select(
f"Choose {Name}'s 2nd language: ",
choices=["Hindi", "Telugu"],
style=minimalStyle,
instruction="\n",
).ask()
elif Class == 4:
# ? Asking for 2nd language name with french
Lang2Name = questionary.select(
f"Choose {Name}'s 2nd language: ",
choices=["Hindi", "Telugu", "French"],
style=minimalStyle,
instruction="\n",
).ask()
elif 5 <= Class <= 8:
# ? Asking for 2nd language name with french
Lang2Name = questionary.select(
f"Choose {Name}'s 2nd language: ",
choices=["Hindi", "Telugu", "French"],
style=minimalStyle,
instruction="\n",
).ask()
# ? Asking for 3rd language name
Lang3Name = IsProperLang3(
questionary.select(
f"Choose {Name}'s 3rd language: ",
choices=["Hindi", "Telugu", "French", "Sanskrit"],
style=minimalStyle,
instruction="\n",
).ask(),
Lang2Name,
)
elif 9 <= Class <= 10:
# ? Asking for 2nd language name with french
Lang2Name = (
questionary.select(
f"Choose {Name}'s 2nd language: ",
choices=["Hindi", "Telugu", "French"],
style=minimalStyle,
instruction="\n",
)
.ask()
.lower()
)
elif Class in [11, 12]:
# ! Categorizing by stream
Stream = (
questionary.select(
f"Choose {Name}'s stream: ",
choices=["MPC", "BiPC", "CEC", "Humanities"],
style=minimalStyle,
instruction="\n",
)
.ask()
.lower()
)
# ? Asking for 5th core name
FcoreName = IsProperFcore(
questionary.select(
f"Choose {Name}'s 5th Core: ",
choices=[
"Mathematics",
"Informatics Practices",
"Psychology",
"Physical Education",
"Fine Arts",
],
style=minimalStyle,
instruction="\n",
).ask(),
Stream,
)
else:
ClearScreen()
print("Enter a valid class.")
continue
break
# ? Clearing Screen
ClearScreen()
# ? Section
Section = IsProperSection(f"Enter {Name}'s section: ")
# ? Roll Number
while True:
try:
RollNum = IsProperRollNum(
abs(
int(
questionary.text(
f"Enter {Name}'s roll number: ", style=minimalStyle
).ask()
)
)
)
break
except:
print("Enter a valid roll number.")
# ? Inserting data into a main table
cur.execute(
f"insert into allstudents values({AdmNum}, '{Name}', {Class}, '{Section}')"
)
# ? Grade one
if Class == 1:
cur.execute(
f"insert into catone(AdmNum, Name, Class, Section, RollNumber, Lang2Name) values({AdmNum}, '{Name}', {Class}, '{Section}', {RollNum}, '{Lang2Name}')"
)
# ? Grade 2 - 4
elif 2 <= Class <= 4:
cur.execute(
f"insert into cattwo(AdmNum, Name, Class, Section, RollNumber, Lang2Name) values({AdmNum}, '{Name}', {Class}, '{Section}', {RollNum}, '{Lang2Name}')"
)
# ? Grade 5 - 8
elif 5 <= Class <= 8:
cur.execute(
f"insert into catthree(AdmNum, Name, Class, Section, RollNumber, Lang2Name, Lang3Name) values({AdmNum}, '{Name}', {Class}, '{Section}', {RollNum}, '{Lang2Name}', '{Lang3Name}')"
)
# ? Grade 9 - 10
elif 9 <= Class <= 10:
cur.execute(
f"insert into catfour(AdmNum, Name, Class, Section, RollNumber, Lang2Name) values({AdmNum}, '{Name}', {Class}, '{Section}', {RollNum}, '{Lang2Name}')"
)
elif 11 <= Class <= 12:
# ? Math, Physics, Chemistry
if Stream.lower() == "mpc":
cur.execute(
f"insert into catfive(AdmNum, Name, Class, Section, RollNumber, FcoreName) values({AdmNum}, '{Name}', {Class}, '{Section}', {RollNum}, '{FcoreName}')"
)
# ? Biology, Physics, Chemistry
elif Stream.lower() == "bipc":
cur.execute(
f"insert into catsix(AdmNum, Name, Class, Section, RollNumber, FcoreName) values({AdmNum}, '{Name}', {Class}, '{Section}', {RollNum}, '{FcoreName}')"
)
# ? Commerce
elif Stream.lower() == "cec":
cur.execute(
f"insert into catseven(AdmNum, Name, Class, Section, RollNumber, FcoreName) values({AdmNum}, '{Name}', {Class}, '{Section}', {RollNum}, '{FcoreName}')"
)
# ? Humanities
elif Stream.lower() == "humanities":
cur.execute(
f"insert into cateight(AdmNum, Name, Class, Section, RollNumber, FcoreName) values({AdmNum}, '{Name}', {Class}, '{Section}', {RollNum}, '{FcoreName}')"
)
con.commit()
ClearScreen()
print(f"{Name} has been successfully added.")
input("Press enter to continue ")
# ! <-- Editing student information -->
def EditStudent():
# ? Clearing Screen
ClearScreen()
# * Admission Number
# ? Getting autocomplete for admission number
cur.execute(f"select AdmNum from allstudents")
a = cur.fetchall()
adm = [str(a[i][0]) for i in range(len(a))]
if len(adm) == 0:
print("You have yet to add a student.")
input("Press enter to continue ")
return None
# ? Getting the actual admission number
while True:
try:
AdmNum = str(
int(
questionary.autocomplete(
f"Enter admission number of the student: ",
adm,
style=minimalStyle,
).ask()
)
)
break
except:
print("Please enter a valid admission number.")
while True:
cur.execute(f"select class from allstudents where AdmNum={AdmNum}")
admNumFetch = cur.fetchall()
try:
if len(admNumFetch) == 0:
raise ValueError
else:
break
except ValueError:
print("This admission number does not exist.")
while True:
try:
AdmNum = str(
int(
questionary.autocomplete(
f"Enter admission number of the student: ",
adm,
style=minimalStyle,
).ask()
)
)
break
except:
print("Please enter a valid admission number")
ClearScreen()
# ? Name
Name = IsProperName(
questionary.text("Enter new student's name: ", style=minimalStyle).ask()
).title()
# ? Old Class
OldClass = admNumFetch[0][0]
OldStream = None
if OldClass in [11, 12]:
# ? Mathematics, Physics, Chemistry
cur.execute(f"select * from catfive where AdmNum={AdmNum}")
streamFetch = cur.fetchall()
if len(streamFetch) != 0:
OldStream = "mpc"
# ? Biology, Physics, Chemistry
cur.execute(f"select * from catsix where AdmNum={AdmNum}")
streamFetch = cur.fetchall()
if len(streamFetch) != 0:
OldStream = "bipc"
# ? Commerce
cur.execute(f"select * from catseven where AdmNum={AdmNum}")
streamFetch = cur.fetchall()
if len(streamFetch) != 0:
OldStream = "cec"
# ? Humanities
cur.execute(f"select * from cateight where AdmNum={AdmNum}")
streamFetch = cur.fetchall()
if len(streamFetch) != 0:
OldStream = "humanities"
# ? New Class
while True:
try:
NewClass = abs(
int(
questionary.text(
f"Enter {Name}'s new class: ", style=minimalStyle
).ask()
)
)
if 1 > NewClass or NewClass > 12:
ClearScreen()
print("Enter a valid class.")
continue
break
except:
print("Please enter a valid class.")
# ? Section
Section = IsProperSection(f"Enter {Name}'s new section: ")
# ? Roll Number
while True:
try:
RollNum = IsProperRollNum(
abs(
int(
questionary.text(
f"Enter {Name}'s new roll number: ", style=minimalStyle
).ask()
)
)
)
break
except:
print("Enter a valid roll number.")
# ? Updating data in the main table
cur.execute(
f"update allstudents set Name='{Name}', Class={NewClass}, Section='{Section}' where AdmNum={AdmNum}"
)
# ? Clearing Screen
ClearScreen()
# ! Choosing new subjects
if 1 <= NewClass <= 3:
# ? Asking for 2nd language name without french
Lang2Name = questionary.select(
f"Choose {Name}'s new 2nd language: ",
choices=["Hindi", "Telugu"],
style=minimalStyle,
instruction="\n",
).ask()
elif NewClass == 4:
# ? Asking for 2nd language name with french
Lang2Name = questionary.select(
f"Choose {Name}'s new 2nd language: ",
choices=["Hindi", "Telugu", "French"],
style=minimalStyle,
instruction="\n",
).ask()
elif 5 <= NewClass <= 8:
# ? Asking for 2nd language name with french
Lang2Name = questionary.select(
f"Choose {Name}'s new 2nd language: ",
choices=["Hindi", "Telugu", "French"],
style=minimalStyle,
instruction="\n",
).ask()
# ? Asking for 3rd language name
Lang3Name = IsProperLang3(
questionary.select(
f"Choose {Name}'s new 3rd language: ",
choices=["Hindi", "Telugu", "French", "Sanskrit"],
style=minimalStyle,
instruction="\n",
).ask(),
Lang2Name,
)
elif 9 <= NewClass <= 10:
# ? Asking for 2nd language name with french
Lang2Name = questionary.select(
f"Choose {Name}'s new 2nd language: ",
choices=["Hindi", "Telugu", "French"],
style=minimalStyle,
instruction="\n",
).ask()
elif NewClass in [11, 12]:
# ! Categorizing by stream
NewStream = (
questionary.select(
f"Choose {Name}'s stream: ",
choices=["MPC", "BiPC", "CEC", "Humanities"],
style=minimalStyle,
instruction="\n",
)
.ask()
.lower()
)
# ? Asking for 5th core name
FcoreName = IsProperFcore(
questionary.select(
f"Choose {Name}'s 5th Core: ",
choices=[
"Mathematics",
"Informatics Practices",
"Psychology",
"Physical Education",
"Fine Arts",
],
style=minimalStyle,
instruction="\n",
).ask(),
NewStream,
)
# ! If class hasn't changed, not deleting entry in particular category.
if OldClass == NewClass:
# ? Grade one
if OldClass == 1:
cur.execute(
f"update catone set Name='{Name}', Class={OldClass}, Section='{Section}', RollNumber={RollNum}, Lang2Name='{Lang2Name}' where AdmNum={AdmNum};"
)
# ? Grade 2 - 4
elif 2 <= OldClass <= 4:
cur.execute(
f"update cattwo set Name='{Name}', Class={OldClass}, Section='{Section}', RollNumber={RollNum}, Lang2Name='{Lang2Name}' where AdmNum={AdmNum};"
)
# ? Grade 5 - 8
elif 5 <= OldClass <= 8:
cur.execute(
f"update catthree set Name='{Name}', Class={OldClass}, Section='{Section}', RollNumber={RollNum}, Lang2Name='{Lang2Name}', Lang3Name='{Lang3Name}' where AdmNum={AdmNum};"
)
# ? Grade 9 - 10
elif 9 <= OldClass <= 10:
cur.execute(
f"update catfour set Name='{Name}', Class={OldClass}, Section='{Section}', RollNumber={RollNum}, Lang2Name='{Lang2Name}' where AdmNum={AdmNum};"
)
elif 11 <= OldClass <= 12:
if NewStream.lower() == OldStream.lower():
# ? Math, Physics, Chemistry
if NewStream.lower() == "mpc":
cur.execute(
f"update catfive set Name='{Name}', Class={OldClass}, Section='{Section}', RollNumber={RollNum}, FcoreName='{FcoreName}' where AdmNum={AdmNum};"
)
# ? Biology, Physics, Chemistry
elif NewStream.lower() == "bipc":
cur.execute(
f"update catsix set Name='{Name}', Class={OldClass}, Section='{Section}', RollNumber={RollNum}, FcoreName='{FcoreName}' where AdmNum={AdmNum};"
)
# ? Commerce
elif NewStream.lower() == "cec":
cur.execute(
f"update catseven set Name='{Name}', Class={OldClass}, Section='{Section}', RollNumber={RollNum}, FcoreName='{FcoreName}' where AdmNum={AdmNum};"
)
# ? Humanities
elif NewStream.lower() == "humanities":
cur.execute(
f"update cateight set Name='{Name}', Class={OldClass}, Section='{Section}', RollNumber={RollNum}, FcoreName='{FcoreName}' where AdmNum={AdmNum};"
)
else:
cur.execute(f"delete from catfive where AdmNum={AdmNum}")
cur.execute(f"delete from catsix where AdmNum={AdmNum}")
cur.execute(f"delete from catseven where AdmNum={AdmNum}")
cur.execute(f"delete from cateight where AdmNum={AdmNum}")
if NewStream.lower() == "mpc":
cur.execute(
f"insert into catfive(AdmNum, Name, Class, Section, Rollnumber, FcoreName) values({AdmNum}, '{Name}', {NewClass}, '{Section}', {RollNum}, '{FcoreName}')"
)
elif NewStream.lower() == "bipc":
cur.execute(
f"insert into catsix(AdmNum, Name, Class, Section, Rollnumber, FcoreName) values({AdmNum}, '{Name}', {NewClass}, '{Section}', {RollNum}, '{FcoreName}')"
)
elif NewStream.lower() == "cec":
cur.execute(
f"insert into catseven(AdmNum, Name, Class, Section, Rollnumber, FcoreName) values({AdmNum}, '{Name}', {NewClass}, '{Section}', {RollNum}, '{FcoreName}')"
)
elif NewStream.lower() == "humanities":
cur.execute(
f"insert into cateight(AdmNum, Name, Class, Section, Rollnumber, FcoreName) values({AdmNum}, '{Name}', {NewClass}, '{Section}', {RollNum}, '{FcoreName}')"
)
# ! If classes are different, deleting entry and creating new entry in respective category.
else:
cur.execute(f"delete from catone where AdmNum={AdmNum}")
cur.execute(f"delete from cattwo where AdmNum={AdmNum}")
cur.execute(f"delete from catthree where AdmNum={AdmNum}")
cur.execute(f"delete from catfour where AdmNum={AdmNum}")
cur.execute(f"delete from catfive where AdmNum={AdmNum}")
cur.execute(f"delete from catsix where AdmNum={AdmNum}")
cur.execute(f"delete from catseven where AdmNum={AdmNum}")
cur.execute(f"delete from cateight where AdmNum={AdmNum}")
if NewClass == 1:
cur.execute(
f"insert into catone(AdmNum, Name, Class, Section, Rollnumber, Lang2Name) values({AdmNum}, '{Name}', {NewClass}, '{Section}', {RollNum} '{Lang2Name}')"
)
elif 2 <= NewClass <= 4:
cur.execute(
f"insert into cattwo(AdmNum, Name, Class, Section, Rollnumber, Lang2Name) values({AdmNum}, '{Name}', {NewClass}, '{Section}', {RollNum}, '{Lang2Name}')"
)
elif 5 <= NewClass <= 8: