From f2d7fb620306b866f675e5fdd3eea8ee50274d8c Mon Sep 17 00:00:00 2001 From: jose-donato Date: Tue, 13 Sep 2022 10:54:54 +0100 Subject: foundation for openbb terminal pro --- i18n/en.yml | 1 + main.py | 39 +++++++++++++++++++++++++++++++++++++++ terminal.py | 18 ++++++++++++++++-- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 main.py diff --git a/i18n/en.yml b/i18n/en.yml index 5cadee94f60..3098b8cfe27 100644 --- a/i18n/en.yml +++ b/i18n/en.yml @@ -1,5 +1,6 @@ en: _home_: Information, guides and support for the OpenBB Terminal + gui: spin uppppppp about: discover the capabilities of the OpenBB Terminal (https://openbb.co/docs) support: pre-populate a support ticket for our team to evaluate survey: fill in our 2-minute survey so we better understand how we can improve the terminal diff --git a/main.py b/main.py new file mode 100644 index 00000000000..b0fb1d39b83 --- /dev/null +++ b/main.py @@ -0,0 +1,39 @@ +import webbrowser +import pandas as pd +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware + +from openbb_terminal import api + +app = FastAPI() + +origins = ["*"] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + + +@app.on_event("startup") +async def runme(): + webbrowser.open("http://localhost:3000") + # webbrowser.open(f"https://pro.openbb.co/?host=http://localhost:{6969}") + + +@app.get("/", status_code=200) +def home(ticker: str, instrument_type: str = "stocks"): + df = pd.DataFrame() + if instrument_type == "stocks": + df = api.stocks.load(ticker) + elif instrument_type == "crypto": + df = api.crypto.load(ticker) + df.reset_index(inplace=True) + df.columns = df.columns.str.lower() + df["date"] = df["date"].dt.strftime("%Y-%m-%d") + # rename date to time + df.rename(columns={"date": "time"}, inplace=True) + return df.to_dict(orient="records") diff --git a/terminal.py b/terminal.py index dd6deab944f..99a4528eda6 100644 --- a/terminal.py +++ b/terminal.py @@ -5,13 +5,13 @@ __docformat__ = "numpy" import argparse import difflib import logging +import webbrowser + import os import platform import sys -import webbrowser from typing import List import dotenv - from prompt_toolkit import PromptSession from prompt_toolkit.completion import NestedCompleter from prompt_toolkit.styles import Style @@ -63,6 +63,7 @@ class TerminalController(BaseController): """Terminal Controller class""" CHOICES_COMMANDS = [ + "gui", "keys", "settings", "survey", @@ -139,6 +140,7 @@ class TerminalController(BaseController): mt.add_raw("\n") mt.add_cmd("news") mt.add_cmd("exe") + mt.add_cmd("gui") mt.add_raw("\n") mt.add_info("_main_menu_") mt.add_menu("stocks") @@ -157,6 +159,18 @@ class TerminalController(BaseController): mt.add_raw("\n") console.print(text=mt.menu_text, menu="Home") + def call_gui(self, other_args: List[str]) -> None: + import uvicorn + + parse = argparse.ArgumentParser( + add_help=False, + prog="gui", + description=translate("gui"), + ) + gui_parser = self.parse_known_args_and_warn(parse, other_args) + if gui_parser: + uvicorn.run("main:app", host="0.0.0.0", port=6969) + def call_news(self, other_args: List[str]) -> None: """Process news command""" parse = argparse.ArgumentParser( -- cgit v1.2.3