-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_import.py
More file actions
105 lines (80 loc) · 2.91 KB
/
run_import.py
File metadata and controls
105 lines (80 loc) · 2.91 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import json
from datetime import datetime
import logging
import math
import pandas as pd
from modules.import_helper import import_helper
def initialize_logging(config, start_time):
run_name = config['run_name']
log_path = config['log_path']
log_level = config['log_level']
# If not exists, create
if not os.path.exists(log_path):
os.makedirs(log_path)
str_date = start_time.strftime("%Y%m%d%H%M%S")
log_file = os.path.join(log_path, f'{str_date}_{run_name}_import.log')
#log_file = f'{log_path}\\{str_date}_{run_name}_import.log'
set_level = logging.INFO
if log_level == 'debug':
set_level = logging.DEBUG
elif log_level == 'info':
set_level = logging.INFO
elif log_level == 'warning':
set_level = logging.WARNING
elif log_level == 'error':
set_level = logging.ERROR
elif log_level == 'critical':
set_level = logging.CRITICAL
logging.basicConfig(
level=set_level,
format="%(asctime)s - [%(levelname)s] - %(message)s",
handlers=[
logging.FileHandler(log_file, 'a'),
logging.StreamHandler()
]
)
return log_file, set_level
def main(argv):
start_time = datetime.now()
if len(argv) > 0:
config_name = argv[0]
#config_name = "config_local_test.json"
#config_name = "config_server_test.json"
#config_name = "config_server_group_1.json"
#config_name = "config_server_group_2.json"
#config_name = "config_server_group_3.json"
#config_name = "config_server_group_4.json"
#config_name = "config_server_group_5.json"
#config_name = "config_server_group_6.json"
#------------------------------------------
# Load Config
#------------------------------------------
with open(config_name) as f:
config = json.load(f)
#------------------------------------------
# Initialize Logging
#------------------------------------------
log_path, log_level = initialize_logging(config, start_time)
logging.info('Import Started')
#------------------------------------------
# Run Validation
#------------------------------------------
helper = import_helper(config, log_path, log_level)
helper.run_import()
#------------------------------------------
# Calculate Duration
#------------------------------------------
end_time = datetime.now()
elapsed_time = end_time - start_time
seconds_in_day = 24 * 60 * 60
duration = divmod(elapsed_time.days * seconds_in_day + elapsed_time.seconds, 60)
logging.info(f'Import Complete - Duration: {duration}')
else:
print('Please enter path to config file')
return None
if __name__ == "__main__":
main(sys.argv[1:])