-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniusingsql.py
370 lines (334 loc) · 14.9 KB
/
uniusingsql.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
class Clas:
total_stu = 0
def __init__(self, first, last, mother, father, roll, clas, phone, mail):
self.first = first
self.last = last
self.mother = mother.capitalize()
self.father = father.capitalize()
self.roll = roll
self.clas = clas
self.phone = phone
self.mail = mail.capitalize()
Clas.total_stu += 1
def fullname(self):
return self.first.capitalize() + " " + self.last.capitalize()
import psycopg2
db = psycopg2.connect(database='student', user='postgres', host='127.0.0.1', password='12345678', port=5432)
cur = db.cursor()
# os=Clas()
# a=os.fullname()
#Note :- Uncomment these two lines when you run code first time to create tables in db then comment again.
# cur.execute('Create table class(name varchar(20),mother varchar(20),father varchar(20),roll bigint,clas varchar(20), phone bigint, mail varchar(40),datetime varchar(35))')
# db.commit()
# state="""INSERT INTO class (name,mother,father,roll,clas,phone,mail) VALUES('%s','%s','%s',%d,'%s',%d,'%s')"""%(a,os.mother,os.father,os.roll,os.clas,os.phone,os.mail)
# cur.execute("insert into class values(%s,%s,%s,%d,%s,%d,%s)"%(os.fullname(),os.mother,os.father,os.roll,os.clas,os.phone,os.mail))
# db.commit()
# cur.execute(state)
# cur.execute('ALTER TABLE class ALTER COLUMN "clas" TYPE varchar(10)')
# db.commit()
def _():
a = [77, 97, 100, 101, 32, 98, 121, 32, 58, 45, 45, 79, 36, 45, 45]
print("-" * 20, end="")
for x in range(len(a)):
print(chr(a[x]), end="")
print("-" * 20)
def dbs():
db = psycopg2.connect(database='student', user='postgres', host='127.0.0.1', password='12345678', port=5432)
cur = db.cursor()
print("!Please Enter your enteries correctly. =")
print("-" * 55)
a = input("Enter your first name = ")
b = input("Enter your last name = ")
c = input("Enter your mother's name = ")
d = input("Enter your Ftaher's name = ")
print("The roll no. should be of 5 digits")
e = int(input("Enter your Rollno ="))
m = str(e)
while len(m) != 5:
print("Try again")
e = int(input("Enter your Rollno Again ="))
m = str(e)
f = input("Enter your class =")
g = input("Enter your phone no =")
p = str(g)
while len(p) != 10:
print("Try again with correct format of phone no.")
g = input("Enter your phone no =")
p = str(g)
h = input("Enter your mail id =")
t = dt()
os = Clas(a, b, c, d, e, f, g, h)
state = """INSERT INTO class (name,mother,father,roll,clas,phone,mail,datetime) VALUES('%s','%s','%s',%d,'%s',%s,'%s','%s')""" % (
os.fullname(), os.mother, os.father, os.roll, os.clas, os.phone, os.mail, t)
cur.execute(state)
db.commit()
i = input("do you want to add more enteries (yes/no)")
return i
def repeat(self, i):
if (i == "yes" or i == "y"):
dbs()
else:
print("Thanks for using dbs system")
def l(ro):
return (" " * (35 - len(str(ro))))
def dt():
import datetime
now = datetime.datetime.now()
return str(now.strftime("%Y-%m-%d %H:%M:%S"))
def check_details():
k = int(input("Enter the roll no = "))
cur.execute("select * from class where roll=%d" % (k))
ro = cur.fetchall()
for row in ro:
print("Here is your details of given roll no = ", k)
print("-" * 55)
print("Name = ", row[0])
print("Mother's name = ", row[1])
print("Father's name = ", row[2])
print("Roll no = ", row[3])
print("Class = ", row[4])
print("Phone = ", row[5])
print("Mail id = ", row[6])
print("_" * 55)
_()
def count_len_of_table():
cur.execute("select *from class")
gh = cur.fetchall()
rs = len(gh)
return rs
def welcomeToDBMS():
print("\n")
print("*"*50)
print("\n")
print("Welcome to the Database Management System ")
print("1. Admin")
print("2. Student")
print("3. Teacher")
print("4. Know About Developer")
print("5. Main menu")
print("6. Exit")
import datetime
now = datetime.datetime.now()
i = int(input("Enter your choice = "))
if (i == 1):
print("-----Welcome to Admin Department------")
print("1. Check Total no. of students ")
print("2. Check student details")
i = int(input("Enter your choice = "))
if (i == 1):
print("Total no. of students are in University is = ", count_len_of_table())
welcomeToDBMS()
elif (i == 2):
k = int(input("Enter the roll no = "))
cur.execute(f"select * from class where roll={k}")
row = cur.fetchall()
print(row)
welcomeToDBMS()
elif (i == 2):
print("1. Check your details")
print("2. Generate id card")
i = int(input("Enter your choice = "))
if (i == 2):
i = int(input("Please Enter the Roll no = "))
j = input("Enter your name = ")
import time
import sys
s = '.'
print("\n", "\n", "\n", "\n", )
sys.stdout.write(' Please wait While loading ')
for z in range(3):
sys.stdout.write(s)
sys.stdout.flush()
time.sleep(0.4)
print("\r")
cur.execute("select * from class where roll=%d" % (i))
record = cur.fetchall()
for row in record:
q = str(now.year)
ro = str(row[3])
ri = str(cur.rowcount + 000)
li = len(q) + len(ro) + len(ri)
print("|" + "-" * 55 + "|")
print("|", " SOL(School of open learning ) " + "|")
print("|" + "-" * 55 + "|")
print("|" + " Identity card " + " |")
print("|", " ----------------- " + "|")
print("| ", "Reg. Date/Time : %s" % (row[7]), l(row[7]) + "|")
print("| ", "Reg. Id : SOl-%s-%s-%s" % (q, ri, ro), " " * (28 - li), "|")
print("|" + " " * 55 + "|")
print("| ", "Name = ", row[0], l(row[0]) + "|")
print("| ", "Mother's name = ", row[1], l(row[1]) + "|")
print("| ", "Father's name = ", row[2], l(row[2]) + "|")
print("| ", "Roll no = ", row[3], l(row[3]) + "|")
print("| ", "Class = ", row[4], l(row[4]) + "|")
print("| ", "Phone = ", row[5], l(row[5]) + "|")
print("| ", "Mail id = ", row[6], l(row[6]) + "|")
print("|" + "-" * 55 + "|")
print("_" * 55)
_()
welcomeToDBMS()
elif (i == 1):
k = int(input("Enter the roll no = "))
cur.execute("select * from class where roll=%d" % (k))
ro = cur.fetchall()
for row in ro:
print("Here is your details of given roll no = ", k)
print("-" * 55)
print("Name = ", row[0])
print("Mother's name = ", row[1])
print("Father's name = ", row[2])
print("Roll no = ", row[3])
print("Class = ", row[4])
print("Phone = ", row[5])
print("Mail id = ", row[6])
print("_" * 55)
_()
welcomeToDBMS()
elif (i == 3):
print("1. Add new student in class.")
print("2. Check Total no. of students are in University.")
print("3. Modify/Update student details.")
print("4. Delete an student data")
i = int(input("Enter the choice = "))
if (i == 1):
i = dbs()
while i == "yes":
dbs()
i = input("Enter the input (yes /no)")
if i == "yes":
pass
else:
welcomeToDBMS()
elif (i == 2):
print("Total no. of students are in University is = ", count_len_of_table())
welcomeToDBMS()
elif (i == 3):
udb = int(input("Enter the student roll no. = "))
cur.execute("select * from class where roll=%d" % (udb))
ro = cur.fetchall()
for row in ro:
print("Here is your details of given roll no = ", udb)
print("-" * 55)
print("1. Name = ", row[0])
print("2. Mother's name = ", row[1])
print("3. Father's name = ", row[2])
print("4. Roll no = ", row[3])
print("5. Class = ", row[4])
print("6. Phone = ", row[5])
print("7. Mail id = ", row[6])
print("-" * 55)
k = int(input("Select the field you want to update = "))
if k == 1:
print("You have selected name =%s for change" % (row[0]))
k = input("Enter the new name with you want to replace the existing name = ")
cur.execute("update class set name = '%s' where name='%s'" % (k.capitalize(), row[0]))
db.commit()
print("Record Updated successfully")
k = input("Do you want to check the updated record?")
if k == "yes" or k == "y":
check_details()
else:
print("-" * 55)
print("Thanks for using Database system...")
print("_" * 55)
_()
elif (k == 2):
print("You have selected Mother's name = %s for change" % (row[1]))
k = input("Enter the new name with you want to replace the existing name = ")
cur.execute("update class set mother = '%s' where mother='%s'" % (k.capitalize(), row[1]))
db.commit()
print("Record Updated successfully")
k = input("Do you want to check the updated record?")
if k == "yes" or k == "y":
check_details()
else:
print("-" * 55)
print("Thanks for using Database system...")
elif k == 3:
print("You have selected Father's name =%s for change" % (row[2]))
k = input("Enter the new name with you want to replace the existing name = ")
cur.execute("update class set father = '%s' where father='%s'" % (k.capitalize(), row[2]))
db.commit()
print("Record Updated successfully")
k = input("Do you want to check the updated record?")
if k == "yes" or k == "y":
check_details()
else:
print("-" * 55)
print("Thanks for using Database system...")
elif k == 4:
print("You have selected Roll no. =%d for change" % (row[3]))
k = int(input("Enter the new Roll no. with you want to replace the existing Roll no. = "))
cur.execute("update class set roll = %d where roll=%d" % (k, row[3]))
db.commit()
print("Record Updated successfully")
k = input("Do you want to check the updated record?")
if k == "yes" or k == "y":
check_details()
else:
print("-" * 55)
print("Thanks for using Database system...")
elif k == 5:
print("You have selected Class =%s for change" % (row[4]))
k = input("Enter the new class with you want to replace the existing class = ")
cur.execute("update class set clas = '%s' where clas='%s'" % (k, row[4]))
db.commit()
print("Record Updated successfully")
k = input("Do you want to check the updated record?")
if k == "yes" or k == "y":
check_details()
else:
print("-" * 55)
print("Thanks for using Database system...")
elif k == 6:
print("You have selected Phone no. =%d for change" % (row[5]))
k = int(input("Enter the new phone no. with you want to replace the existing phone no. = "))
cur.execute("update class set phone = %d where phone=%d" % (k, row[5]))
db.commit()
print("Record Updated successfully")
k = input("Do you want to check the updated record?")
if k == "yes" or k == "y":
check_details()
else:
print("-" * 55)
print("Thanks for using Database system...")
elif k == 7:
print("You have selected Email-id =%s for change" % (row[6]))
k = input("Enter the new mail id with you want to replace the existing mail id = ")
cur.execute("update class set mail = '%s' where mail='%s'" % (k.capitalize(), row[6]))
db.commit()
print("Record Updated successfully")
k = input("Do you want to check the updated record?")
if k == "yes" or k == "y":
check_details()
else:
print("-" * 55)
print("Thanks for using Database system...")
print("_" * 55)
_()
welcomeToDBMS()
elif (i == 4):
print("_" * 55)
print("Name = Orendra singh")
print("Phone no. = demo")
print("Email-id = [email protected]")
print('Follow me on Instagram "www.instagram.com/orendrasingh"')
print("_" * 55)
_()
welcomeToDBMS()
elif (i==5):
welcomeToDBMS()
elif (i==6):
print("Thanks for using our school management system")
exit()
else:
print("Wrong input")
welcomeToDBMS()
# i=dbs()
# while i=="yes":
# dbs()
# i=input("Enter the input (yes /no)")
# if i =="yes":
# pass
# else:
# quit()