mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
* comment call_news * remove news * remove keys controller * remove settings controller * remove ta forex * remove qa economy * remove ta stocks * remove qa stocks * remove fa stocks * remove ins stocks * remove gov stocks * remove dps stocks * remove ba stocks * remove bt stocks * remove stocks * remove stocks base controller class * ruff * remove qa forex * remove oanda * remove forex * remove forex * remove forex * remove mention to fx_tickers * remove ta crypto * remove qa crypto * remove dd crypto * remove crypto controller * remove crypto references * remove economy controller * remove economy folder * remoe etf controller * remove reports controller * remove dashboards controller * remove alt controller * rmeove etf files * remove alt files * remove custom reports * remove dashboard files * remove econometrics controller * remove forecast controller * remove reports files * remove forecast files * remove econometrics files * remove portfolio * remove futures * remove fixedincome * remove funds * remove sdk and common * remove all from init * remove reference to ipykernel * remove reference to ta_helpers * remove reference to ta_helpers * cleanup * adjustments to choices * remove old sdk generator * remove mention to dashboards * ruff * cleanup * remove logging infra * remove decorators * remove sdk audit * remove tought of the day * remove tought of the day * fix commands andmenus choices * fixing lints * ruffs * remove old tests
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
from argparse_translator.argparse_class_processor import ArgparseClassProcessor
|
|
from openbb_terminal.base_platform_controller import PlatformController
|
|
|
|
|
|
class PlatformControllerFactory:
|
|
def __init__(self, platform_router: type):
|
|
self.platform_router = platform_router
|
|
self._translated_target = ArgparseClassProcessor(
|
|
target_class=self.platform_router
|
|
)
|
|
self.router_name = (
|
|
str(type(self.platform_router))
|
|
.rsplit(".", maxsplit=1)[-1]
|
|
.replace("'>", "")
|
|
.replace("ROUTER_", "")
|
|
.lower()
|
|
)
|
|
self.controller_name = f"{self.router_name.capitalize()}Controller"
|
|
|
|
def create(self) -> type:
|
|
ClassName = self.controller_name
|
|
Parents = (PlatformController,)
|
|
Attributes = {"CHOICES_GENERATION": True}
|
|
|
|
# Menu and Command choices generation
|
|
choices_menus = []
|
|
choices_commands = []
|
|
translators = self._translated_target.translators
|
|
paths = self._translated_target.paths
|
|
# menus
|
|
for key, value in paths.items():
|
|
if value == "path":
|
|
continue
|
|
choices_menus.append(key)
|
|
# commands
|
|
for name, _ in translators.items():
|
|
if any(f"{self.router_name}_{path}" in name for path in paths):
|
|
continue
|
|
new_name = name.replace(f"{self.router_name}_", "")
|
|
choices_commands.append(new_name)
|
|
|
|
Attributes["CHOICES_MENUS"] = choices_menus
|
|
Attributes["CHOICES_COMMANDS"] = choices_commands
|
|
|
|
# Use type to create the class
|
|
DynamicClass = type(ClassName, Parents, Attributes)
|
|
|
|
return DynamicClass
|