2021-08-23 06:14:40 +00:00
|
|
|
import importlib
|
|
|
|
import logging
|
2021-08-17 02:51:42 +00:00
|
|
|
|
2021-08-23 06:14:40 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
2021-08-17 02:51:42 +00:00
|
|
|
|
2021-08-23 06:14:40 +00:00
|
|
|
logger = logging.getLogger("api")
|
2021-08-17 02:51:42 +00:00
|
|
|
|
2021-08-23 06:14:40 +00:00
|
|
|
api = FastAPI()
|
2021-12-01 06:22:22 +00:00
|
|
|
api_data = {"version": "2021.12.1.0", "author": "Riley Housden"}
|
2021-08-17 02:51:42 +00:00
|
|
|
|
|
|
|
|
2021-08-23 06:14:40 +00:00
|
|
|
def load_module(name: str):
|
|
|
|
module = importlib.import_module(name)
|
|
|
|
api.include_router(module.router)
|
|
|
|
logger.info(f"Loaded module: {module.__name__}")
|
2021-08-17 02:51:42 +00:00
|
|
|
|
|
|
|
|
2021-08-23 06:14:40 +00:00
|
|
|
for m_path in Path("routers").glob("*"):
|
|
|
|
if "__pycache__" in m_path.parts or "__init__" == m_path.stem:
|
|
|
|
continue
|
|
|
|
load_module(str(m_path).replace("/", ".").replace(".py", ""))
|
2021-08-17 02:51:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
@api.get("/")
|
|
|
|
def quack():
|
2021-08-23 06:14:40 +00:00
|
|
|
return api_data
|