-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (29 loc) · 1.17 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
import argparse
import os
from http.server import HTTPServer
from typing import Dict
import urllib3
from common.http_get_handler import HttpGetHandler
from common.settings import Settings
from models.param_names import ParamNames
def parse_console_args_and_get_settings() -> Dict:
args_parser = argparse.ArgumentParser()
args_parser.add_argument(f"--{ParamNames.UTIL_PORT}", type=int,
default=os.environ.get(f"{ParamNames.UTIL_PORT.upper()}", default=9119))
args_parser.add_argument(f"--{ParamNames.CONFIG_FILE}", type=str,
default=os.environ.get(f"{ParamNames.CONFIG_FILE.upper()}", default="config.json"))
args_dict = args_parser.parse_args().__dict__
return args_dict
def main():
urllib3.disable_warnings()
args_dict = parse_console_args_and_get_settings()
settings = Settings(args_dict)
http_get_handler = HttpGetHandler
http_get_handler.settings = settings
web_server = HTTPServer(("", settings.util_port), http_get_handler)
try:
web_server.serve_forever()
except KeyboardInterrupt:
web_server.server_close()
if __name__ == '__main__':
main()