-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
90 lines (69 loc) · 3.08 KB
/
main.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
from venv import logger
from src.util.tkinter_gui_manager import execute_app # from src.util.pyqt_geo_manager import execute_app
from src.AutomationScriptsDir.auto_write_storage_containers_and_blobs_to_json import \
auto_write_storage_containers_and_blobs_to_json
from src.util.utilitiesFunctions import *
import json
import datetime
import logging
import sys
import traceback
class LoggerWriter:
def __init__(self, level, logger):
self.level = level
self.logger = logger
def write(self, message):
if message != '\n':
self.logger.log(self.level, message)
def flush(self):
pass
def func_main_logger():
"""
### Now you can log messages like this:
logger.info('This is an info message.')
logger.error('This is an error message.')
try:
1 / 0
except Exception as ex:
logger.error(f"Exception: XXX_function has been failed: >>> {ex} >>> {traceback.extract_tb(list(sys.exc_info())[2])}")
"""
# Logger Name
logger_name = f'{fjp()["paths"]["PushExpDataPathRel"]}/{fjp(jsname="log.json")["current_press"]}/{load_json("log.json")["current_press"]}_{datetime.datetime.now().strftime("%Y-%m-%d")}_{load_json("conf.json")["logApp"]["AppLogName"]}'
# Set up the logger
logger = logging.getLogger(logger_name)
logger.setLevel(logging.DEBUG)
# Create a file handler
handler = logging.FileHandler(f'{logger_name}.csv')
handler.setLevel(logging.NOTSET)
# Create a logging format
formatter = CustomFormatter()
handler.setFormatter(formatter)
# Add the handlers to the logger
logger.addHandler(handler)
# Redirect stdout and stderr
sys.stdout = LoggerWriter(logging.INFO, logger)
sys.stderr = LoggerWriter(logging.ERROR, logger)
########################################################################################################################
########################################################################################################################
########################################################################################################################
if __name__ == '__main__':
# TODO: Manage all folders and utilities files before running the main()
# TODO: Delete folders which are older then 1 week.
# TODO: Adding timeFrame availability
# TODO:
# 1. Logger Initializing
func_main_logger()
# 2. Main application
bkg_thread_00 = func_sub_processes(tar=execute_app, nm='execute_app')
# 3. Reading JSONs
logger.info(fjp('conf.json'))
logger.info(fjp('log.json')['current_press'])
print(json.dumps(config_variables, indent=4))
# 4. Getting Data from Azure
try:
bkg_thread_01 = func_sub_processes(tar=auto_write_storage_containers_and_blobs_to_json,
nm='auto_write_storage_containers_and_blobs_to_json')
except Exception as ex:
print(f"Exception: auto_write_storage_containers_and_blobs_to_json has been failed: >>> {ex} >>> {traceback.extract_tb(list(sys.exc_info())[2])}")
bkg_thread_01.join()
bkg_thread_00.join()