Init
This commit is contained in:
62
Application/app.py
Normal file
62
Application/app.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from ..Convention.Runtime.GlobalConfig import ProjectConfig, ConsoleFrontColor
|
||||
from ..CoreModules.flags import set_internal_verbose
|
||||
from .web import app
|
||||
from argparse import ArgumentParser
|
||||
from typing import *
|
||||
import sys
|
||||
import uvicorn
|
||||
|
||||
def main() -> int:
|
||||
config = ProjectConfig()
|
||||
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("--main-webhook-url", type=str, default=config.FindItem("main_webhook_url", ""))
|
||||
parser.add_argument("--host", type=str, default=config.FindItem("host", "0.0.0.0"))
|
||||
parser.add_argument("--port", type=int, default=config.FindItem("port", 8000))
|
||||
parser.add_argument("--verbose", type=bool, default=config.FindItem("verbose", False))
|
||||
args = parser.parse_args()
|
||||
|
||||
config.SaveProperties()
|
||||
|
||||
if "help" in args:
|
||||
parser.print_help()
|
||||
return 0
|
||||
|
||||
# region Main Webhook URL
|
||||
|
||||
webhook_url = args.main_webhook_url
|
||||
if not webhook_url or webhook_url == "":
|
||||
config.Log("Fatal", f"{ConsoleFrontColor.RED}Main webhook URL is not set{ConsoleFrontColor.RESET}")
|
||||
return 1
|
||||
|
||||
config.Log("Info", f"{ConsoleFrontColor.GREEN}Main webhook URL: {webhook_url}{ConsoleFrontColor.RESET}")
|
||||
|
||||
# endregion Main Webhook URL
|
||||
|
||||
# region Verbose
|
||||
|
||||
verbose = args.verbose
|
||||
set_internal_verbose(verbose)
|
||||
|
||||
config.Log("Info", f"{ConsoleFrontColor.GREEN}Verbose: {verbose}{ConsoleFrontColor.RESET}")
|
||||
|
||||
# endregion Verbose
|
||||
|
||||
# region Server
|
||||
|
||||
host = args.host
|
||||
port = args.port
|
||||
config.Log("Info", f"{ConsoleFrontColor.GREEN}Server: {host}:{port}{ConsoleFrontColor.RESET}")
|
||||
|
||||
# endregion Server
|
||||
|
||||
uvicorn.run(app, host=host, port=port,
|
||||
limit_concurrency=5,
|
||||
log_level="info")
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
__all__ = ["main"]
|
||||
Reference in New Issue
Block a user