forked from rbshadow/Student-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.py
More file actions
150 lines (128 loc) · 4.22 KB
/
Copy pathstudent.py
File metadata and controls
150 lines (128 loc) · 4.22 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
import os
import platform
import csv
import time
from prettytable import from_csv
import header_design as design
import main
import preloader
tab = '\t'
operating_system = platform.system()
def id_generator():
id_list = []
default_student_id = 1001
try:
with open('student_database.csv', 'r') as fr:
data = csv.reader(fr)
for student_id in data:
id_list.append(student_id[0])
student_id = int(id_list[-1]) + 1
return student_id
except Exception:
return default_student_id
# Adding New Student
def student_input():
if operating_system == 'Linux':
os.system('clear')
elif operating_system == 'Windows':
os.system('cls')
design.art('New Student Form')
student_id = id_generator()
first_name = input('[+] Enter first name: ')
middle_name = input('[+] Enter middle name: ')
last_name = input('[+] Enter last name: ')
age = input('[+] Enter age: ')
gender = input('[+] Enter gender: ')
department = input('[+] Enter department: ')
while True:
confirm = input('\n[!] Do you want to save? (y/n): ').lower()
if confirm == 'y':
if middle_name:
name = first_name + ' ' + middle_name + ' ' + last_name
# Saving information
with open('student_database.csv', 'a', newline='') as fs:
data = csv.writer(fs)
data.writerow([student_id, name, age, gender, department])
else:
name = first_name + ' ' + last_name
# Saving information
with open('student_database.csv', 'a', newline='') as fs:
data = csv.writer(fs)
data.writerow([student_id, name, age, gender, department])
print()
msg = '[!] Please wait. \n\n' + tab * 4 + 'Saving'
for i in range(5):
preloader.load(msg)
print('\n[✔] Saved')
time.sleep(.5)
main.StartMain.main(self='self')
break
elif confirm == 'n':
print()
msg = tab * 4 + '[!] Please wait'
for i in range(5):
preloader.load(msg)
time.sleep(.5)
main.StartMain.main(self='self')
break
else:
print()
print('[X] Wrong Input!')
time.sleep(.50)
# Show student database
def student_database():
if operating_system == 'Linux':
os.system('clear')
elif operating_system == 'Windows':
os.system('cls')
design.art('Student Database')
try:
with open('student_database.csv', 'r') as fr:
data_table = from_csv(fr, field_names=['Student ID', 'Student Name', 'Age', 'Gender', 'Department'])
# Show student database
print(data_table)
except Exception as e:
print(e)
print('\nNot data available. Please add some student first.\n')
choice = input('\nPlease enter your choice:\n'
'[1] Main Menu\n'
'\n'
'admin@sms:~$ ')
if choice == '1':
main.StartMain.main(self='self')
else:
print()
print('[X] Wrong Input!')
time.sleep(.50)
if operating_system == 'Linux':
os.system('clear')
elif operating_system == 'Windows':
os.system('cls')
student_database()
def search_student(search='id'):
if search == 'id':
print('[1] Searching by ID')
elif search == 'first_name':
print('[2] Searching by First Name')
def search():
if operating_system == 'Linux':
os.system('clear')
elif operating_system == 'Windows':
os.system('cls')
choice = input('Please enter your choice:\n'
'[1] Search by ID\n'
'[2] Search by First Name\n'
'[3] Back to Main Menu\n'
'\n'
'admin@sms:~$ ')
if choice is '1':
search_student(search='id')
elif choice is '2':
search_student(search='first_name')
elif choice is '3':
pass
else:
print()
print('[X] Wrong Input!')
time.sleep(.50)
search()