-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrusguard.py
70 lines (53 loc) · 2.23 KB
/
rusguard.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
from datetime import datetime,date,timedelta
import json
import pyodbc
class RusGuardApi():
def __init__(self):
with open('conf.json') as f:
self.data = json.load(f)
if self.data['selected_version'] == "rusguard":
self.con = pyodbc.connect('Driver={SQL Server};'
f"Server={self.data['rusguard_server_name']};"
'Database=RusGuardDB;'
'Trusted_Connection=yes;')
def get_events(self,todayday):
print(todayday)
cur = self.con.cursor()
cur.execute(f"SELECT DateTime,Message,EmployeeID from [dbo].[Log] WHERE DateTime BETWEEN '{todayday.strftime('%Y-%m-%d')} 00:00:00' AND '{todayday.strftime('%Y-%m-%d')} 23:59:59';")
events = cur.fetchall()
print(events)
return events
def collect_events(self,todayday):
collect_events = []
events = self.get_events(todayday)
print("sad")
for event in events:
message = event[1]
userID = event[2]
dateTo = event[0]
datetime_object = datetime.strftime(dateTo, '%Y-%m-%d %H:%M:%S')
cursor = self.con.cursor()
if userID != None:
userExecute = cursor.execute(f"SELECT Comment,FirstName,SecondName,LastName FROM [dbo].[Employee] WHERE [_id]='{userID}'")
user = userExecute.fetchone()
iin = user[0]
fullName = f"{user[1]} {user[2]} {user[3]}"
if message == 'Выход':
collect_events.append(
(
iin,
fullName,
0,
datetime_object.strftime("%d.%m.%Y %H:%M:%S"),
todayday
))
elif message == 'Вход':
collect_events.append(
(
iin,
fullName,
1,
datetime_object.strftime("%d.%m.%Y %H:%M:%S"),
todayday
))
return collect_events