-
Notifications
You must be signed in to change notification settings - Fork 0
/
average.py
62 lines (54 loc) · 1.97 KB
/
average.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
import mysql.connector as sqlcon
import getpass
conexao = sqlcon.connect(
host='localhost',
user='root',
password='1234',
database='bdinfosecurity',
)
try:
name= input("Enter username:")
passw= getpass.getpass(prompt="Enter password:")
validate = conexao.cursor()
comando=f"select user.userid from bdinfosecurity.user where user.username = '{name}' and user.userpassword = '{passw}' and user.userrole='admin'"
validate.execute(comando)
queryresult=validate.fetchone()
for row in queryresult:
idsession=row
if idsession != None:
validation = "ok"
print("login concluido")
else:
validation = None
print("acesso negado")
validate.close()
except:
validation = None
print("acesso negado")
if(validation=="ok"):
cursor = conexao.cursor()
comando='select user.userethnicity,count(user.userethnicity) as etnia from bdinfosecurity.user where user.userethnicity is not null group by user.userethnicity'
cursor.execute(comando)
resultado=cursor.fetchall()
print("Contagem de atnias dos usuários")
print(resultado)
cursor.close()
cursor = conexao.cursor()
comando='select user.userage,count(user.userage) as etnia from bdinfosecurity.user where user.userage is not null group by user.userage'
cursor.execute(comando)
resultado=cursor.fetchall()
print("Contagem de idades dos usuários")
print(resultado)
cursor.close()
cursor = conexao.cursor()
comando='select user.usergender,count(user.usergender) as etnia from bdinfosecurity.user where user.usergender is not null group by user.usergender'
cursor.execute(comando)
resultado=cursor.fetchall()
print("Contagem de genero dos usuários")
print(resultado)
cursor.close()
log = conexao.cursor()
comando=f"insert into bdinfosecurity.accesslog (iduseracces, context) values ({idsession}, 'geração de indicadores')"
log.execute(comando)
conexao.commit()
log.close()