Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,17 +2,21 @@ from fastapi import FastAPI, HTTPException
|
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from pydantic import BaseModel
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
app = FastAPI(title="Stock / Index Backend")
|
| 18 |
|
|
|
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from pydantic import BaseModel
|
| 4 |
|
| 5 |
+
import os
|
| 6 |
+
import importlib
|
| 7 |
+
|
| 8 |
+
# ---------- Auto-import all .py files in current folder ----------
|
| 9 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 10 |
+
|
| 11 |
+
for file in os.listdir(current_dir):
|
| 12 |
+
if file.endswith(".py") and file not in ["app.py", "__init__.py"]:
|
| 13 |
+
module_name = file[:-3] # remove '.py'
|
| 14 |
+
try:
|
| 15 |
+
globals()[module_name] = importlib.import_module(module_name)
|
| 16 |
+
print(f"Imported module: {module_name}")
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print(f"Failed to import {module_name}: {e}")
|
| 19 |
+
|
| 20 |
|
| 21 |
app = FastAPI(title="Stock / Index Backend")
|
| 22 |
|