-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperco_web.py
95 lines (77 loc) · 3.1 KB
/
perco_web.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
from datetime import datetime,date,timedelta
import json
import pyodbc
from mysql import connector
class PercoWebApi():
def __init__(self):
with open('conf.json') as f:
self.data = json.load(f)
if self.data['selected_version'] == "perco_web":
self.con = connector.connect(
host=self.data['percoweb']['host'],
user=self.data['percoweb']['user'],
password=self.data['percoweb']['password'],
database=self.data['percoweb']['database'],
port=self.data['percoweb']['port']
)
def get_events(self,todayday):
# print(todayday)
print(self.con)
cur = self.con.cursor()
cur.execute(
f"SELECT time_label, event_type, device_id, user_id from event WHERE time_label BETWEEN '{todayday.strftime('%Y-%m-%d')} 00:00:00' AND '{todayday.strftime('%Y-%m-%d')} 23:59:59' AND event_type = 17 ORDER BY time_label DESC;"
)
events = cur.fetchall()
# print(events, 'get_events')
return events
def get_events_month(self,todayday):
# print(todayday)
today = datetime.date()
cur = self.con.cursor()
cur.execute(
f"SELECT time_label, event_type, device_id, user_id from event WHERE time_label BETWEEN '{todayday.strftime('%Y-%m-%d')} 00:00:00' AND '{todayday.strftime('%Y-%m-%d')} 23:59:59' AND event_type = 17 ORDER BY time_label DESC;"
)
events = cur.fetchall()
# print(events, 'get_events')
return events
def collect_events(self,todayday, month=False):
collect_events = []
if month:
events = self.get_events_month(todayday)
else:
events = self.get_events(todayday)
for event in events:
message = event[2]
userID = event[3]
dateTo = event[0]
datetime_object = datetime.strftime(dateTo, "%d.%m.%Y %H:%M:%S")
cursor = self.con.cursor()
if userID != None:
try:
cursor.execute(
f"SELECT tabel_number,user_id FROM user_staff WHERE user_id = {userID}")
user = cursor.fetchone()
iin = user[0]
fullName = user[0]
except Exception as e:
pass
# print(userID, e, event)
if message == 2:
collect_events.append(
(
iin,
fullName,
0,
datetime_object,
todayday
))
elif message == 1:
collect_events.append(
(
iin,
fullName,
1,
datetime_object,
todayday
))
return collect_events