mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
fix app startup event (#7554)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
# pylint: disable=W0212,W0613
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import Any
|
||||
|
||||
from openbb_core.app.model.command_context import CommandContext
|
||||
@@ -19,6 +20,12 @@ router = Router(prefix="")
|
||||
COT_CHOICES: list[dict[str, str | dict[str, str | None]]] = []
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def _cot_router_lifespan(_):
|
||||
await build_choices()
|
||||
yield
|
||||
|
||||
|
||||
async def build_choices():
|
||||
"""Build the choices for Workspace."""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
@@ -28,10 +35,17 @@ async def build_choices():
|
||||
choices: list[dict[str, str | dict[str, str | None]]] = []
|
||||
|
||||
for d in contracts:
|
||||
description = (
|
||||
f"{getattr(d, 'subcategory', '').strip() or getattr(d, 'commodity_name', '').strip()}"
|
||||
f" | {getattr(d, 'code', '').strip()}"
|
||||
)
|
||||
choice: dict[str, str | dict[str, str | None]] = {
|
||||
"label": d.name.strip(), # type: ignore
|
||||
"value": d.code.strip(), # type: ignore
|
||||
"extraInfo": {"description": f"{d.subcategory.strip()} | {d.code.strip()}", "rightOfDescription": ""}, # type: ignore
|
||||
"label": getattr(d, "name", "").strip(),
|
||||
"value": getattr(d, "code", "").strip(),
|
||||
"extraInfo": {
|
||||
"description": description,
|
||||
"rightOfDescription": "",
|
||||
},
|
||||
}
|
||||
choices.append(choice)
|
||||
|
||||
@@ -40,7 +54,7 @@ async def build_choices():
|
||||
COT_CHOICES = choices
|
||||
|
||||
|
||||
router.api_router.add_event_handler("startup", build_choices)
|
||||
router.api_router.lifespan_context = _cot_router_lifespan
|
||||
|
||||
|
||||
async def get_cot_choices() -> list[dict[str, str | dict[str, str | None]]]:
|
||||
|
||||
Reference in New Issue
Block a user