-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathHelpers.py
69 lines (50 loc) · 2.08 KB
/
Helpers.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
############################################################################################
#
# Project: Peter Moss Acute Myeloid & Lymphoblastic Leukemia AI Research Project
# Repository: ALL Detection System 2019
# Project: Facial Authentication Server
#
# Author: Adam Milton-Barker (AdamMiltonBarker.com)
# Contributors:
# Title: Helper Class
# Description: Helper class for the ALL Detection System 2019.
# License: MIT License
# Last Modified: 2020-07-14
#
############################################################################################
import json
import time
from datetime import datetime
class Helpers():
""" ALL Detection System 2019 Helper Class
Common helper functions for the ALL Detection System 2019 Facial Authentication Server project.
"""
def __init__(self):
""" Initializes the Helper class. """
self.confs = self.loadConfs()
def loadConfs(self):
""" Loads the configuration. """
confs = {}
with open('Required/confs.json') as confs:
confs = json.loads(confs.read())
return confs
def currentDateTime(self):
""" Gets the current date and time in words. """
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def timerStart(self):
""" Starts the timer. """
return str(datetime.now()), time.time()
def timerEnd(self, start):
""" Ends the timer. """
return time.time(), (time.time() - start), str(datetime.now())
def setLogFile(self, path):
""" Ends a log file path. """
return path + datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d-%H-%M-%S') + ".txt"
def logMessage(self, logfile, process, messageType, message, hide=False):
""" Logs a message to a log file. """
logString = datetime.fromtimestamp(time.time()).strftime(
'%Y-%m-%d %H:%M:%S') + "|" + process + "|" + messageType + ": " + message
with open(logfile, "a") as logLine:
logLine.write(logString+'\r\n')
if hide == False:
print(logString)