-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputer Project.py
More file actions
418 lines (408 loc) · 13.7 KB
/
Computer Project.py
File metadata and controls
418 lines (408 loc) · 13.7 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
#Imports and Startup definitions for Crime Reporting Software
import mysql.connector as c
import time
import os
from datetime import date
today=date.today()
cnx=c.connect(host="localhost",user="root",password="root",charset="utf8")
crs=cnx.cursor()
crs.execute("create database if not exists login")
crs.execute("use login")
def startup():
crs.execute("create table if not exists login (Num int(2) primary key AUTO_INCREMENT,User varchar(25) unique,Pass varchar(12),Phoneno int(10),Admin varchar(1))")
crs.execute("insert ignore into login values(1,'root','root',100,'y')")
crs.execute("create table if not exists crime (Num int(2) primary key AUTO_INCREMENT,Crime varchar(25),Location varchar(12),Date DATE,Description varchar(125),User varchar(25))")
cnx.commit()
menu()
#Login and Register purposes
def login():
os.system('CLS')
user=input("Enter your Username: ")
print()
passs=input("Enter your Password: ")
crs.execute("select pass from login where user='{}'".format(user))
check=crs.fetchall()
for i in check:
if i[0]==str(passs):
global x
x=user
mainmenu(user)
def register():
os.system('CLS')
user=input("Enter your Username: ")
print()
passs=input("Enter your Password: ")
print()
pass_check=input("ReEnter your Password: ")
print()
phno=int(input("Enter your Phone Number: "))
ad="n"
if passs==pass_check:
crs.execute("insert into login (user,pass,phoneno,admin) values('{}','{}',{},'{}')".format(user,passs,phno,ad))
cnx.commit()
os.system('CLS')
print("Registering....")
time.sleep(3)
print("Registered Successfully!")
menu()
else:
os.system('CLS')
print("Recheck Failed, Retry!")
time.sleep(2)
register()
def chngpass(user):
os.system('CLS')
usr=input("Enter the Password: ")
crs.execute("update login set pass='{}' where user='{}'".format(usr,x))
cnx.commit()
os.system('CLS')
print("Changing Password.....")
time.sleep(1)
print("Successfully Changed!")
time.sleep(2)
def menu():
os.system('CLS')
print('\n'*10)
print("+--------------------------+\n")
print("MENU".center(25))
print('-'*28)
print()
print("1.Login(Sign IN)\n".center(12))
print("2.Register(Sign UP) (3.exit)".center(12))
print("+--------------------------+\n")
while True:
try:
r=int(input("Enter your choice: "))
break
except ValueError:
os.system('CLS')
print("Errored!. Reconnecting....")
time.sleep(2)
menu()
if r==1:
login()
elif r==2:
register()
elif r==3:
os.system('CLS')
print("Call 100 For Further Assistance")
time.sleep(2)
os.system('CLS')
exit()
else:
print("Returning to menu.....")
time.sleep(3)
menu()
#Mainmenu for all users to report crimes
def mainmenu(user=7):
crs.execute("select admin from login where user='{}'".format(user))
check=crs.fetchall()
if user==7:
menu()
os.system('cls')
print("Logging in!")
time.sleep(1)
os.system('cls')
print("+--------------------------+\n")
print("MAINMENU".center(25))
print('-'*28)
print()
print("1.Crime Reporting\n\n2.History\n\n3.Change Password\n\n4.Logout")
for i in check:
if i[0]=="y":
print("\n5.Admin Menu")
print("+--------------------------+\n")
while True:
try:
r=int(input("Enter your choice: "))
break
except ValueError:
os.system('CLS')
print("Errored!. Reconnecting....")
time.sleep(2)
mainmenu(user)
if r==1:
crime()
elif r==2:
history()
elif r==3:
print(user)
chngpass(user)
elif r==4:
print("Logging Out!....")
global x
del x
time.sleep(3)
menu()
elif r==5:
for i in check:
if i[0]=="y":
admin()
else:
mainmenu(x)
#Shows all reported crime by the logged in user
def history():
crs.execute("select * from crime where user='{}'".format(x))
check=crs.fetchall()
print("+--------------------------------+\n")
for i in check:
print(" | Crime Number : ",i[0],"\n | Crime : ",i[1],"\n | Location : ",i[2],"\n | Date : ",i[3],"\n | Description : ",i[4],"\n | User Reported : ",i[5],"\n")
print("+--------------------------------+\n")
c=input("Enter To Continue")
mainmenu(x)
#Crime reporting menu
def crime():
os.system('CLS')
print('\n'*10)
print("+--------------------------+\n")
print("TYPES OF CRIMES".center(25))
print('-'*25)
print("1.TRAFFIC\n\n2.ASSAULT\n\n3.THEFT\n\n4.CYBER\n\n5.TRAFFICKING\n\n6.DRUGS")
print("+--------------------------+\n")
while True:
try:
crime=int(input("Enter your choice: "))
break
except ValueError:
os.system('CLS')
print("Errored!. Reconnecting....")
time.sleep(2)
mainmenu(x)
if crime==1:
crm="Traffic"
elif crime==2:
crm="Assault"
elif crime==3:
crm="Theft"
elif crime==4:
crm="Cyber"
elif crime==5:
crm="Trafficking"
elif crime==6:
crm="Drugs"
#os.system('cls')
print()
loc=input("Enter the location of the crime: ")
date=today.strftime("%d/%m/%Y")
print()
desc=input("Enter a description for further evidence: ")
crs.execute("insert into crime (crime,location,date,description,user) values('{}','{}',now(),'{}','{}')".format(crm,loc,desc,x))
cnx.commit()
os.system('cls')
print("Reporting Crime ....")
time.sleep(2)
os.system('cls')
print("Thank You For Your Service!")
time.sleep(3)
mainmenu(x)
#Admin section
def admin():
os.system('cls')
print("Logging in!")
time.sleep(1)
os.system('cls')
print('\n'*10)
print("+--------------------------+\n")
print("ADMIN MENU".center(25))
print('-'*25)
print("1.USER DATA\n\n2.CRIME DATA")
print("+--------------------------+\n")
while True:
try:
r=int(input("Enter your choice: "))
break
except ValueError:
os.system('CLS')
print("Errored!. Reconnecting....")
time.sleep(2)
mainmenu(x)
if r==1:
userdata()
if r==2:
crimedata()
else:
mainmenu(x)
#Records of user data
def userdata():
os.system('cls')
print('\n'*10)
print("+--------------------------+\n")
print("USER DATA".center(25))
print('-'*25)
print("1.SHOW ALL USERS\n\n2.SEARCH BY USERNAME\n\n3.SEARCH BY PHONE NO\n\n4.CHANGE USERDATA")
print("+--------------------------+\n")
while True:
try:
r=int(input("Enter your choice: "))
break
except ValueError:
os.system('CLS')
print("Errored!. Reconnecting....")
time.sleep(2)
userdata()
if r==1:
crs.execute("select * from login")
check=crs.fetchall()
print("+--------------------------+\n")
for i in check:
print(" | User Number : ",i[0],"\n | User Name : ",i[1],"\n | Phone Number : ",i[3],"\n | Admin : ",i[4],"\n")
print("+--------------------------+\n")
c=input("Enter To Continue")
userdata()
elif r==2:
c=input("Enter the UserName to search: ")
crs.execute("select * from login where user='{}'".format(c))
check=crs.fetchall()
print("+--------------------------+\n")
for i in check:
print(" | User Number : ",i[0],"\n | User Name : ",i[1],"\n | Phone Number : ",i[3],"\n | Admin : ",i[4],"\n")
print("+--------------------------+\n")
c=input("Enter To Continue")
userdata()
elif r==3:
c=input("Enter the Phone No to search: ")
crs.execute("select * from login where phoneno={}".format(c))
check=crs.fetchall()
print("+--------------------------+\n")
for i in check:
print(" | User Number : ",i[0],"\n | User Name : ",i[1],"\n | Phone Number : ",i[3],"\n | Admin : ",i[4],"\n")
print("+--------------------------+\n")
c=input("Enter To Continue")
userdata()
elif r==4:
os.system('cls')
print('\n'*10)
print("+--------------------------+\n")
print("USER DATA".center(25))
print('-'*25)
print("1.CHANGE USERNAME\n\n2.CHANGE PASSWORD\n\n3.CHANGE ADMIN PRIVILAGES\n\n4.DELETE USER")
print("+--------------------------+\n")
while True:
try:
k=int(input("Enter your choice: "))
break
except ValueError:
os.system('CLS')
print("Errored!. Reconnecting....")
time.sleep(2)
userdata()
if k==1:
os.system('CLS')
chng=input("Enter the User to change: ")
print()
usr=input("Enter the UserName: ")
crs.execute("update login set user='{}' where user='{}'".format(usr,chng))
cnx.commit()
os.system('CLS')
print("Changing UserName.....")
time.sleep(1)
print("Successfully Changed!")
time.sleep(2)
elif k==2:
os.system('CLS')
chng=input("Enter the User to change: ")
print()
usr=input("Enter the Password: ")
crs.execute("update login set pass='{}' where user='{}'".format(usr,chng))
cnx.commit()
os.system('CLS')
print("Changing Password.....")
time.sleep(1)
print("Successfully Changed!")
time.sleep(2)
elif k==3:
os.system('CLS')
chng=input("Enter the User to change: ")
print()
usr=input("Change Admin Privilages(y/n): ")
crs.execute("update login set admin='{}' where user='{}'".format(usr,chng))
cnx.commit()
os.system('CLS')
print("Changing Privilages.....")
time.sleep(1)
print("Successfully Changed!")
time.sleep(2)
elif k==4:
os.system('CLS')
chng=input("Enter the User to DELETE: ")
print()
crs.execute("delete from login where user='{}'".format(chng))
cnx.commit()
os.system('CLS')
print("Deleting User.....")
time.sleep(1)
print("Successfully Deleted!")
time.sleep(2)
else:
userdata()
else:
admin()
#Records of crime data
def crimedata():
os.system('CLS')
print('\n'*10)
print("+--------------------------+\n")
print("CRIME DATA".center(25))
print('-'*25)
print("1.SHOW ALL REPORTS\n\n2.SEARCH BY CRIME\n\n3.SEARCH BY USER\n\n4.SEARCH BY CRIME NUMBER")
print("+--------------------------+\n")
while True:
try:
k=int(input("Enter your choice: "))
break
except ValueError:
os.system('CLS')
print("Errored!. Reconnecting....")
time.sleep(2)
crimedata()
if k==1:
crs.execute("select * from crime")
check=crs.fetchall()
print("+--------------------------------+\n")
for i in check:
print(" | Crime Number : ",i[0],"\n | Crime : ",i[1],"\n | Location : ",i[2],"\n | Date : ",i[3],"\n | Description : ",i[4],"\n | User Reported : ",i[5],"\n")
print("+--------------------------------+\n")
c=input("Enter To Continue")
crimedata()
elif k==2:
c=input("Enter the Crime to search: ")
crs.execute("select * from crime where crime='{}'".format(c))
check=crs.fetchall()
print("+--------------------------------+\n")
for i in check:
print(" | Crime Number : ",i[0],"\n | Crime : ",i[1],"\n | Location : ",i[2],"\n | Date : ",i[3],"\n | Description : ",i[4],"\n | User Reported : ",i[5],"\n")
print("+--------------------------------+\n")
c=input("Enter To Continue")
crimedata()
elif k==3:
c=input("Enter the User to search: ")
crs.execute("select * from crime where user='{}'".format(c))
check=crs.fetchall()
print("+--------------------------------+\n")
for i in check:
print(" | Crime Number : ",i[0],"\n | Crime : ",i[1],"\n | Location : ",i[2],"\n | Date : ",i[3],"\n | Description : ",i[4],"\n | User Reported : ",i[5],"\n")
print("+--------------------------------+\n")
c=input("Enter To Continue")
crimedata()
elif k==4:
c=input("Enter the Crime Number to search: ")
crs.execute("select * from crime where num='{}'".format(c))
check=crs.fetchall()
print("+--------------------------------+\n")
for i in check:
print(" | Crime Number : ",i[0],"\n | Crime : ",i[1],"\n | Location : ",i[2],"\n | Date : ",i[3],"\n | Description : ",i[4],"\n | User Reported : ",i[5],"\n")
print("+--------------------------------+\n")
c=input("Enter To Continue")
crimedata()
else:
admin()
#For error checking
startup()
while True:
try:
x
time.sleep(3)
mainmenu(x)
except NameError:
time.sleep(3)
menu()