move host, port and debug to server run function make .env variables writen in CAPS

This commit is contained in:
2024-04-13 01:22:54 +02:00
parent 4b179bc452
commit 0027476c4e
2 changed files with 11 additions and 13 deletions
+7 -7
View File
@@ -22,16 +22,16 @@ import os
if __name__ == "__main__":
load_dotenv(find_dotenv())
SNAKE = SnakeBuilder.build(os.environ.get("snake", "DummSnake"))
server = Server(
data_path=os.path.dirname(__file__),
snake=SnakeBuilder.build(os.environ.get("snake", "DummSnake")),
port=int(os.environ.get("PORT", "8000")),
debug=bool(os.environ.get("debug", False)),
snake=SnakeBuilder.build(os.environ.get("SNAKE", "DummSnake")),
)
if os.environ.get("store_game", None):
if os.environ.get("STORE_GAME_HISTORY", None):
server.enable_store_game_state()
server.run()
server.run(
host=os.environ.get("HOST", "0.0.0.0"),
port=int(os.environ.get("PORT", "8000")),
debug=bool(os.environ.get("DEBUG", False))
)
+4 -6
View File
@@ -10,9 +10,7 @@ import logging, json, os
class Server:
default_snake_config = {"apiversion":"1","author":"","color":"#888888","head":"default","tail":"default"}
def __init__(self, data_path:str, snake:TemplateSnake, host:str="0.0.0.0", port:str="8000", debug:bool=False):
self.host = host
self.port = port
def __init__(self, data_path:str, snake:TemplateSnake, debug:bool=False):
self.debug = debug
self.snake = snake
@@ -50,11 +48,11 @@ class Server:
)
return response
def run(self):
def run(self, host:str="0.0.0.0", port:str="8000", debug:bool=False):
logging.getLogger("werkzeug").setLevel(logging.ERROR)
print(f"\nRunning Battlesnake at http://{self.host}:{self.port} with the {self.snake.__class__.__name__.replace('Snake', '')} Snake")
self.app.run(host=self.host, port=self.port, debug=self.debug)
print(f"\nRunning Battlesnake at http://{host}:{port} with the {self.snake.__class__.__name__.replace('Snake', '')} Snake")
self.app.run(host=host, port=port, debug=debug)
def _read_json_config_or_create(self):
snake_config = read_file(self.config_file, json.load)