25 lines
859 B
Python
25 lines
859 B
Python
import sqlite3
|
|
from datetime import datetime
|
|
from models.log import Log
|
|
from models.database import Database
|
|
|
|
class LogService:
|
|
@staticmethod
|
|
def create_log(username, description, additional_information, suspicious):
|
|
now = datetime.now()
|
|
date_string = now.strftime("%d-%m-%Y")
|
|
time_string = now.strftime("%H:%M:%S")
|
|
new_log = Log(Database.connection, None, username, date_string, time_string, description, additional_information, suspicious)
|
|
|
|
new_log.save()
|
|
|
|
@staticmethod
|
|
def get_latest_logs():
|
|
cur = Database.connection.cursor()
|
|
cur.execute("SELECT * FROM logs ORDER BY id DESC LIMIT 100;")
|
|
rows = cur.fetchall()
|
|
logs = []
|
|
for row in rows:
|
|
log = Log(Database.connection)._set_row_values(row)
|
|
logs.append(log)
|
|
return logs |