mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-08 10:22:09 +00:00
* Added github actions for gitflow * Minor changes * Fix plot look when using eval and add query to choices (#3881) (#3898) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> * Testing Gitflow (#3899) * testing gitflow * Name changes * Testing python changes * Added Checkout to Base test * Feature/gitflow (#3900) * Fix plot look when using eval and add query to choices (#3881) (#3901) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> * Gitflow Implementations (#3902) * testing gitflow * Name changes * Testing python changes * Added Checkout to Base test * More minor fixes for merge * Minor fix * Added nightly build * Gitflow Implementations (#3904) * testing gitflow * Name changes * Testing python changes * Added Checkout to Base test * More minor fixes for merge * Minor fix * Added nightly build * Testing Merge * Main --> develop (#3906) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> * GItflow Implementations (#3909) * testing gitflow * Name changes * Testing python changes * Added Checkout to Base test * More minor fixes for merge * Minor fix * Added nightly build * Testing Merge * Merge error fix * Feature/gitflow (#3911) * testing gitflow * Name changes * Testing python changes * Added Checkout to Base test * More minor fixes for merge * Minor fix * Added nightly build * Testing Merge * Merge error fix * Merge fix * merge fix * Merge fix * Merge fix * Merge fix * merge fix * Update develop (#3913) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> * Feature/gitflow (#3914) * testing gitflow * Name changes * Testing python changes * Added Checkout to Base test * More minor fixes for merge * Minor fix * Added nightly build * Testing Merge * Merge error fix * Merge fix * merge fix * Merge fix * Merge fix * Merge fix * merge fix * [Gitflow] - Minor fix * Feature/gitflow (#3921) * testing gitflow * Name changes * Testing python changes * Added Checkout to Base test * More minor fixes for merge * Minor fix * Added nightly build * Testing Merge * Merge error fix * Merge fix * merge fix * Merge fix * Merge fix * Merge fix * merge fix * [Gitflow] - Minor fix * Feature/gitflow (#3914) (#3915) * testing gitflow * Name changes * Testing python changes * Added Checkout to Base test * More minor fixes for merge * Minor fix * Added nightly build * Testing Merge * Merge error fix * Merge fix * merge fix * Merge fix * Merge fix * Merge fix * merge fix * [Gitflow] - Minor fix * Nightly build feature * Added branch name docs * poetry add ccxt@latest (#3920) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * poetry add ccxt@latest Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> * Add crypto dd functions to sdk (#3888) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Add crypto dd functions to sdk * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * Fixes currency and trailmap Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> * Integration tests refactor (#3781) * generate integration tests report * new console report * simple run_scripts * move tests script to folder * add skipping * always display skips * func name * allow running from relative path * rename some vars and time * typo * change portfolio supress and warning * uncomment economy test * rename test controller * multiprocessing * display test progress and available * rename func * mypy * should not be here * small changes * type hinting and docstrings * new subprocesses default * forget context and chunksize * clean len skipt * small comment * fix subproc default with v * minor change * fix path * better this way * make output visible * allow only sequential run with verbose mode * change message * detail * include andrew idea * limit multiprocessing to clone version * fix for package application * must be up here * allow verbose with multiprocessing but warn * update readme * move tests to core * Update README.md * Update README.md * move readme outside * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * parse subproc arg * Update README.md * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * Delete glossary base command * move scripts * ruff * update pyproject.toml * update yfinance * fix futures and economy test, rewrite * rewrite stocks test yfinance dependent * refactor sia to yfinance 0.2... * fix last failing sia tests * black * update reqs Co-authored-by: James Maslek <jmaslek11@gmail.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: Chavithra PARANA <chavithra@gmail.com> * Gitflow - Autodoc (#3922) * Hotfix/dots sources (#3928) * fix: wordwrap * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * fix: str Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> * Update dependency: grpcio (#3937) * Update grpcio * Revert "Update grpcio" This reverts commit 676c50a2bdde5ca64614bddd3eaebbccd68c5994. * Update dependencies * Rebase develop? (#3935) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> * Update installation guides with videos (#3903) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Update installation guides with videos * Add fix for Ruff crashing * Me no longer do what James said * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Jeroen Bouma <jeroenbouma@Jeroens-MacBook-Pro.local> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> * broken link (#3889) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * broken link due to quandl.com redirecting to nasdaq.com, for the link to work and get the appropiate API key you need to remove the period at the end of this link... Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: james <jmaslek11@gmail.com> * Issue #3882 Fixed (#3885) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Issue #3882 Fixed * 2 files reformatted by black * tests added * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * fixed mypy errors Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> * GitFlow - improve check for changes (#3948) Gitflow Implementation * Rewrite and skip yfinance tests (#3953) * economy * fix futures * fix stocks tests * skip unfixable tests * fix ark * Fixed failing badge not used anymore (#3932) Co-authored-by: James Maslek <jmaslek11@gmail.com> * Fix portfolio returns (#3931) * fix inception bug and clean some useless attributes * reorder attributes * add returns and cumulative returns * fix cumulative returns * fix cumulative returns * remove cumulative ret * add some doc and encapsule methods * order detail * add more details on docstrings * wrong docstring * add commnet * Update portfolio_engine.py * fix bug with unsupported type * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * fix table header * fix portfolio integration test * ruff * fix tests * rewrite yfinance call * fix test_draw * test_stocks_helper * bt model * fix comp analysis * fix ftd * fix dd * fix screener Co-authored-by: James Maslek <jmaslek11@gmail.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt> * Put yf.info behind an exchange flag on `load` (#3951) * Put yf.info behind an exchange flag * Guides Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> * Last Price Bug into Previous Close #3865 (#3949) Co-authored-by: James Maslek <jmaslek11@gmail.com> * Add multiple countries option to events (#3938) * allow multiple countries in events cmd * fix test * fix last test * black Co-authored-by: James Maslek <jmaslek11@gmail.com> * Minor Fix for branch name check (#3979) * Gitflow - Added manual trigger to Linting (#3981) * Minor Fix for branch name check * added manual trigger to linting * Linting fix (#3984) Linting fix * Feature/macro convert (#3924) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Issue #3882 Fixed * 2 files reformatted by black * tests added * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * fixed mypy errors * Fixed parser options for currency conversion Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> * Update sma.md (#3956) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * Update sma.md Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> * Update overlap_model.py (#3955) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * Update overlap_model.py Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> * Update vwap.md (#3971) Co-authored-by: James Maslek <jmaslek11@gmail.com> * Update overlap_model.py - wrong typehint (#3970) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * Update overlap_model.py Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> * Bump yfinance to 0.2.4 and fix tests (#3977) * upgrade yfinance to 0.2.4 * fix some tests failing bc yfinance new date format * fix remaining tests * fix tests * rewrite failing test * black * rerecord test * fix get_1y_sp500 test * missing import here Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt> Co-authored-by: James Maslek <jmaslek11@gmail.com> * Add extra error handling for yf in etf (#3985) * Fix the news command and making it more stable (#3965) Co-authored-by: James Maslek <jmaslek11@gmail.com> * Hotfix/bug #3945 (#3963) * Add exception to http requests made by ftd * Formatting Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> * Fix #3787 (#3966) Make the get_equal_weights handle portfolio's with stock's filtered out, due to the stocks having to many NaNs. Co-authored-by: James Maslek <jmaslek11@gmail.com> * Add ticker to the load export file (#3997) * bump * Change export name to have the ticker * revert yaml * Feature/release branch gitflow (#3998) * release branch gitflow implentation * Fix integration tests bugs (#3993) * fix tk * fix newsletters * fix lt * exception on pir * fix attrib bug and remove warning * fix earnings * fix ins, lt, whatif * fillna * fix vis Co-authored-by: James Maslek <jmaslek11@gmail.com> * change .env loading priority (#4005) * [FIX] Pytorch-lightning trainer conflict with TQDM progress bar (#4002) * fix for tqdm progress bar conflict * fix tests Co-authored-by: James Maslek <jmaslek11@gmail.com> * bump * Update release branch * revert conda yaml * logging hash * Fix historical futures plot axes (#4006) * change start date to model * rewrite test * ruff * add end date * move futures and update test * return if wrong dates * fix controller test * record mode rewrite model and view Co-authored-by: James Maslek <jmaslek11@gmail.com> * Update version number * Added scipy to intel * Fix M1 build (#4010) * Fix plot look when using eval and add query to choices (#3881) * convert index to datetime and update choices * uncomment economy integration test * fix treasury concat bug * fix datasets concat on duplciates * Lock ruff version so that new lints dont break our CI (#3905) * Lock ruff version so that new lints dont break our CI * Bumped pre-commit ruff version * adding xgboost explicitly * testing juan sugestion * removing unncessary stuff that the hook deals with Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> * Add xgboost to intel * add scipy libs to windows only * add scipy sparse * update scipy and pywin * update tests * UPdate installation.md to reflect 2.2 * fix yf unit tests * Try to get futures tests working * Ignore tz in yf download * Found another end date needed * delelte yf cache Co-authored-by: luqazino@gmail.com <luqazino@gmail.com> Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: Chavithra PARANA <chavithra@gmail.com> Co-authored-by: jose-donato <43375532+jose-donato@users.noreply.github.com> Co-authored-by: Jeroen Bouma <jer.bouma@gmail.com> Co-authored-by: Jeroen Bouma <jeroenbouma@Jeroens-MacBook-Pro.local> Co-authored-by: Rob-Rychs <Robrychel@gmail.com> Co-authored-by: Mert Nuhuz <mail@mertnuhuz.com> Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt> Co-authored-by: Bongani Bendile <58882596+Bonganibendi@users.noreply.github.com> Co-authored-by: Sergio A. S <sergio-abu@proton.me> Co-authored-by: northern-64bit <75195383+northern-64bit@users.noreply.github.com> Co-authored-by: martinb-bb <105685594+martinb-bb@users.noreply.github.com>
554 lines
20 KiB
Python
554 lines
20 KiB
Python
"""Settings Controller Module"""
|
|
__docformat__ = "numpy"
|
|
|
|
# IMPORTATION STANDARD
|
|
import os
|
|
import os.path
|
|
import argparse
|
|
import logging
|
|
from pathlib import Path
|
|
from typing import List
|
|
import pytz
|
|
|
|
# IMPORTATION THIRDPARTY
|
|
from dotenv import set_key
|
|
|
|
# IMPORTATION INTERNAL
|
|
from openbb_terminal import config_plot as cfg_plot
|
|
from openbb_terminal import feature_flags as obbff
|
|
from openbb_terminal.core.config.paths import USER_ENV_FILE, USER_DATA_DIRECTORY
|
|
from openbb_terminal.custom_prompt_toolkit import NestedCompleter
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.helper_funcs import (
|
|
get_flair,
|
|
get_user_timezone_or_invalid,
|
|
replace_user_timezone,
|
|
set_user_data_folder,
|
|
)
|
|
from openbb_terminal.menu import session
|
|
from openbb_terminal.parent_classes import BaseController
|
|
from openbb_terminal.rich_config import console, MenuText
|
|
|
|
# pylint: disable=too-many-lines,no-member,too-many-public-methods,C0302
|
|
# pylint: disable=import-outside-toplevel
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class SettingsController(BaseController):
|
|
"""Settings Controller class"""
|
|
|
|
CHOICES_COMMANDS: List[str] = [
|
|
"dt",
|
|
"autoscaling",
|
|
"dpi",
|
|
"backend",
|
|
"height",
|
|
"width",
|
|
"pheight",
|
|
"pwidth",
|
|
"monitor",
|
|
"lang",
|
|
"tz",
|
|
"userdata",
|
|
"source",
|
|
"flair",
|
|
"colors",
|
|
]
|
|
PATH = "/settings/"
|
|
|
|
all_timezones = [tz.replace("/", "_") for tz in pytz.all_timezones]
|
|
|
|
languages_available = [
|
|
lang.strip(".yml")
|
|
for lang in os.listdir(obbff.i18n_dict_location)
|
|
if lang.endswith(".yml")
|
|
]
|
|
|
|
def __init__(self, queue: List[str] = None, env_file: str = str(USER_ENV_FILE)):
|
|
"""Constructor"""
|
|
super().__init__(queue)
|
|
self.env_file = env_file
|
|
|
|
if session and obbff.USE_PROMPT_TOOLKIT:
|
|
choices: dict = {c: {} for c in self.controller_choices}
|
|
choices["tz"] = {c: None for c in self.all_timezones}
|
|
choices["lang"] = {c: None for c in self.languages_available}
|
|
self.completer = NestedCompleter.from_nested_dict(choices)
|
|
|
|
def print_help(self):
|
|
"""Print help"""
|
|
mt = MenuText("settings/")
|
|
mt.add_info("_info_")
|
|
mt.add_raw("\n")
|
|
mt.add_cmd("colors")
|
|
mt.add_setting("dt", obbff.USE_DATETIME)
|
|
mt.add_cmd("flair")
|
|
mt.add_raw("\n")
|
|
mt.add_param("_flair", get_flair())
|
|
mt.add_raw("\n")
|
|
mt.add_cmd("lang")
|
|
mt.add_raw("\n")
|
|
mt.add_param("_language", obbff.USE_LANGUAGE)
|
|
mt.add_raw("\n")
|
|
mt.add_cmd("userdata")
|
|
mt.add_raw("\n")
|
|
mt.add_param(
|
|
"_user_data_folder",
|
|
USER_DATA_DIRECTORY,
|
|
)
|
|
mt.add_raw("\n")
|
|
mt.add_cmd("tz")
|
|
mt.add_raw("\n")
|
|
mt.add_param("_timezone", get_user_timezone_or_invalid())
|
|
mt.add_raw("\n")
|
|
mt.add_setting("autoscaling", obbff.USE_PLOT_AUTOSCALING)
|
|
if obbff.USE_PLOT_AUTOSCALING:
|
|
mt.add_cmd("pheight")
|
|
mt.add_cmd("pwidth")
|
|
mt.add_raw("\n")
|
|
mt.add_param("_plot_height_pct", cfg_plot.PLOT_HEIGHT_PERCENTAGE, 16)
|
|
mt.add_param("_plot_width_pct", cfg_plot.PLOT_WIDTH_PERCENTAGE, 16)
|
|
else:
|
|
mt.add_cmd("height")
|
|
mt.add_cmd("width")
|
|
mt.add_raw("\n")
|
|
mt.add_param("_plot_height", cfg_plot.PLOT_HEIGHT, 12)
|
|
mt.add_param("_plot_width", cfg_plot.PLOT_WIDTH, 12)
|
|
mt.add_raw("\n")
|
|
mt.add_cmd("dpi")
|
|
mt.add_raw("\n")
|
|
mt.add_param("_dpi", cfg_plot.PLOT_DPI)
|
|
mt.add_raw("\n")
|
|
mt.add_cmd("backend")
|
|
mt.add_raw("\n")
|
|
mt.add_param("_backend", cfg_plot.BACKEND)
|
|
mt.add_raw("\n")
|
|
mt.add_cmd("monitor")
|
|
mt.add_raw("\n")
|
|
mt.add_param("_monitor", cfg_plot.MONITOR)
|
|
mt.add_raw("\n")
|
|
mt.add_cmd("source")
|
|
mt.add_raw("\n")
|
|
mt.add_param("_data_source", obbff.PREFERRED_DATA_SOURCE_FILE)
|
|
mt.add_raw("\n")
|
|
console.print(text=mt.menu_text, menu="Settings")
|
|
|
|
@log_start_end(log=logger)
|
|
def call_colors(self, _):
|
|
"""Process colors command"""
|
|
console.print(
|
|
"\n1. Play with the terminal coloring embedded in our website https://openbb.co/customize\n"
|
|
)
|
|
console.print("2. Once happy, click 'Download Theme'\n")
|
|
console.print(
|
|
"3. The file 'openbb_config.richstyle.json' should be downloaded\n"
|
|
)
|
|
console.print(
|
|
"4. Insert that config file inside /OpenBBUserData/styles/user/\n"
|
|
)
|
|
console.print("5. Close the terminal and run it again.\n")
|
|
|
|
@log_start_end(log=logger)
|
|
def call_dt(self, _):
|
|
"""Process dt command"""
|
|
obbff.USE_DATETIME = not obbff.USE_DATETIME
|
|
set_key(USER_ENV_FILE, "OPENBB_USE_DATETIME", str(obbff.USE_DATETIME))
|
|
|
|
@log_start_end(log=logger)
|
|
def call_source(self, other_args: List[str]):
|
|
"""Process source command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="source",
|
|
description="Preferred data source file.",
|
|
)
|
|
parser.add_argument(
|
|
"-v",
|
|
"--value",
|
|
type=str,
|
|
default=os.getcwd() + os.path.sep + "sources.json.default",
|
|
dest="value",
|
|
help="value",
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "-v")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser:
|
|
try:
|
|
|
|
the_path = os.getcwd() + os.path.sep + ns_parser.value
|
|
console.print("Loading sources from " + the_path)
|
|
with open(the_path):
|
|
# Try to open the file to get an exception if the file doesn't exist
|
|
pass
|
|
|
|
except Exception as e:
|
|
console.print("Couldn't open the sources file!")
|
|
console.print(e)
|
|
obbff.PREFERRED_DATA_SOURCE_FILE = ns_parser.value
|
|
set_key(
|
|
USER_ENV_FILE,
|
|
"OPENBB_PREFERRED_DATA_SOURCE_FILE",
|
|
str(ns_parser.value),
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_autoscaling(self, _):
|
|
"""Process autoscaling command"""
|
|
obbff.USE_PLOT_AUTOSCALING = not obbff.USE_PLOT_AUTOSCALING
|
|
set_key(
|
|
USER_ENV_FILE,
|
|
"OPENBB_USE_PLOT_AUTOSCALING",
|
|
str(obbff.USE_PLOT_AUTOSCALING),
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_dpi(self, other_args: List[str]):
|
|
"""Process dpi command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="dpi",
|
|
description="Dots per inch.",
|
|
)
|
|
parser.add_argument(
|
|
"-v",
|
|
"--value",
|
|
type=int,
|
|
dest="value",
|
|
help="value",
|
|
required="-h" not in other_args,
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "-v")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser and ns_parser.value:
|
|
set_key(USER_ENV_FILE, "OPENBB_PLOT_DPI", str(ns_parser.value))
|
|
cfg_plot.PLOT_DPI = ns_parser.value
|
|
|
|
@log_start_end(log=logger)
|
|
def call_height(self, other_args: List[str]):
|
|
"""Process height command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="height",
|
|
description="select plot height (autoscaling disabled)",
|
|
)
|
|
parser.add_argument(
|
|
"-v",
|
|
"--value",
|
|
type=int,
|
|
dest="value",
|
|
help="value",
|
|
required="-h" not in other_args,
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "-v")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser:
|
|
set_key(USER_ENV_FILE, "OPENBB_PLOT_HEIGHT", str(ns_parser.value))
|
|
cfg_plot.PLOT_HEIGHT = ns_parser.value
|
|
|
|
@log_start_end(log=logger)
|
|
def call_width(self, other_args: List[str]):
|
|
"""Process width command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="width",
|
|
description="select plot width (autoscaling disabled)",
|
|
)
|
|
parser.add_argument(
|
|
"-v",
|
|
"--value",
|
|
type=int,
|
|
dest="value",
|
|
help="value",
|
|
required="-h" not in other_args,
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "-v")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser:
|
|
set_key(USER_ENV_FILE, "OPENBB_PLOT_WIDTH", str(ns_parser.value))
|
|
cfg_plot.PLOT_WIDTH = ns_parser.value
|
|
|
|
@log_start_end(log=logger)
|
|
def call_pheight(self, other_args: List[str]):
|
|
"""Process pheight command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="pheight",
|
|
description="select plot height percentage (autoscaling enabled)",
|
|
)
|
|
parser.add_argument(
|
|
"-v",
|
|
"--value",
|
|
type=int,
|
|
dest="value",
|
|
help="value",
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "-v")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser:
|
|
set_key(
|
|
USER_ENV_FILE,
|
|
"OPENBB_PLOT_HEIGHT_PERCENTAGE",
|
|
str(ns_parser.value),
|
|
)
|
|
cfg_plot.PLOT_HEIGHT_PERCENTAGE = ns_parser.value
|
|
|
|
@log_start_end(log=logger)
|
|
def call_pwidth(self, other_args: List[str]):
|
|
"""Process pwidth command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="pwidth",
|
|
description="select plot width percentage (autoscaling enabled)",
|
|
)
|
|
parser.add_argument(
|
|
"-v",
|
|
"--value",
|
|
type=float,
|
|
dest="value",
|
|
help="value",
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "-v")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser:
|
|
set_key(
|
|
USER_ENV_FILE,
|
|
"OPENBB_PLOT_WIDTH_PERCENTAGE",
|
|
str(ns_parser.value),
|
|
)
|
|
cfg_plot.PLOT_WIDTH_PERCENTAGE = ns_parser.value
|
|
|
|
@log_start_end(log=logger)
|
|
def call_monitor(self, other_args: List[str]):
|
|
"""Process pwidth command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="pwidth",
|
|
description="choose which monitor to scale: 0-primary, 1-secondary (autoscaling enabled)",
|
|
)
|
|
parser.add_argument(
|
|
"-v",
|
|
"--value",
|
|
type=int,
|
|
dest="value",
|
|
help="value",
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "-v")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser:
|
|
set_key(USER_ENV_FILE, "OPENBB_MONITOR", str(ns_parser.value))
|
|
cfg_plot.MONITOR = ns_parser.value
|
|
|
|
@log_start_end(log=logger)
|
|
def call_backend(self, other_args: List[str]):
|
|
"""Process backend command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="backend",
|
|
description="Backend to use for plotting",
|
|
)
|
|
parser.add_argument(
|
|
"-v",
|
|
"--value",
|
|
type=str,
|
|
dest="value",
|
|
help="value",
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "-v")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser:
|
|
set_key(USER_ENV_FILE, "OPENBB_BACKEND", str(ns_parser.value))
|
|
if ns_parser.value == "None":
|
|
cfg_plot.BACKEND = None # type: ignore
|
|
else:
|
|
cfg_plot.BACKEND = ns_parser.value
|
|
|
|
@log_start_end(log=logger)
|
|
def call_lang(self, other_args: List[str]):
|
|
"""Process lang command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="lang",
|
|
description="Choose language for terminal",
|
|
)
|
|
parser.add_argument(
|
|
"-v",
|
|
"--value",
|
|
type=str,
|
|
dest="value",
|
|
help="Language",
|
|
choices=self.languages_available,
|
|
default="",
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "-v")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser:
|
|
if ns_parser.value:
|
|
set_key(USER_ENV_FILE, "OPENBB_USE_LANGUAGE", str(ns_parser.value))
|
|
obbff.USE_LANGUAGE = ns_parser.value
|
|
else:
|
|
console.print(
|
|
f"Languages available: {', '.join(self.languages_available)}"
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_tz(self, other_args: List[str]):
|
|
"""Process tz command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
description="""
|
|
Setting a different timezone
|
|
""",
|
|
)
|
|
parser.add_argument(
|
|
"-t",
|
|
dest="timezone",
|
|
help="Choose timezone",
|
|
required="-h" not in other_args,
|
|
choices=self.all_timezones,
|
|
)
|
|
|
|
if other_args and "-t" not in other_args[0]:
|
|
other_args.insert(0, "-t")
|
|
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser:
|
|
if ns_parser.timezone:
|
|
replace_user_timezone(ns_parser.timezone.replace("_", "/", 1))
|
|
|
|
@log_start_end(log=logger)
|
|
def call_flair(self, other_args: List[str]):
|
|
"""Process flair command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="flair",
|
|
description="set the flair emoji to be used",
|
|
)
|
|
parser.add_argument(
|
|
"-e",
|
|
"--emoji",
|
|
type=str,
|
|
dest="emoji",
|
|
help="flair emoji to be used",
|
|
nargs="+",
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "-e")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
if ns_parser:
|
|
if not ns_parser.emoji:
|
|
ns_parser.emoji = ""
|
|
else:
|
|
ns_parser.emoji = " ".join(ns_parser.emoji)
|
|
set_key(USER_ENV_FILE, "OPENBB_USE_FLAIR", str(ns_parser.emoji))
|
|
obbff.USE_FLAIR = ns_parser.emoji
|
|
|
|
@log_start_end(log=logger)
|
|
def call_userdata(self, other_args: List[str]):
|
|
"""Process userdata command"""
|
|
parser = argparse.ArgumentParser(
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
prog="userdata",
|
|
description="Set folder to store user data such as exports, presets, logs",
|
|
)
|
|
parser.add_argument(
|
|
"--folder",
|
|
type=str,
|
|
dest="folder",
|
|
help="Folder where to store user data. ",
|
|
default=f"{str(Path.home() / 'OpenBBUserData')}",
|
|
)
|
|
if other_args and "-" not in other_args[0][0]:
|
|
other_args.insert(0, "--folder")
|
|
ns_parser = self.parse_simple_args(parser, other_args)
|
|
|
|
if ns_parser:
|
|
if other_args or self.queue:
|
|
if other_args:
|
|
userdata_path = ""
|
|
else:
|
|
# Re-add the initial slash for an absolute directory provided
|
|
userdata_path = "/"
|
|
|
|
userdata_path += "/".join([ns_parser.folder] + self.queue)
|
|
self.queue = []
|
|
|
|
userdata_path = userdata_path.replace("'", "").replace('"', "")
|
|
|
|
default_path = Path.home() / "OpenBBUserData"
|
|
|
|
success_userdata = False
|
|
while not success_userdata:
|
|
if userdata_path.upper() == "DEFAULT":
|
|
console.print(
|
|
f"User data to be saved in the default folder: '{default_path}'"
|
|
)
|
|
set_user_data_folder(
|
|
self.env_file, path_folder=str(default_path)
|
|
)
|
|
success_userdata = True
|
|
else:
|
|
# If the path selected does not start from the user root, give relative location from root
|
|
if userdata_path[0] == "~":
|
|
userdata_path = userdata_path.replace(
|
|
"~", os.path.expanduser("~")
|
|
)
|
|
|
|
# Check if the directory exists
|
|
if os.path.isdir(userdata_path):
|
|
console.print(
|
|
f"User data to be saved in the selected folder: '{userdata_path}'"
|
|
)
|
|
set_user_data_folder(
|
|
self.env_file, path_folder=userdata_path
|
|
)
|
|
success_userdata = True
|
|
else:
|
|
console.print(
|
|
"[red]The path selected to user data does not exist![/red]\n"
|
|
)
|
|
user_opt = "None"
|
|
while user_opt not in ("Y", "N"):
|
|
user_opt = input(
|
|
f"Do you wish to create folder: `{userdata_path}` ? [Y/N]\n"
|
|
).upper()
|
|
|
|
if user_opt == "Y":
|
|
os.makedirs(userdata_path)
|
|
console.print(
|
|
f"[green]Folder '{userdata_path}' successfully created.[/green]"
|
|
)
|
|
set_user_data_folder(
|
|
self.env_file, path_folder=userdata_path
|
|
)
|
|
else:
|
|
# Do not update userdata_folder path since we will keep the same as before
|
|
console.print(
|
|
"[yellow]User data to keep being saved in "
|
|
+ f"the selected folder: {str(USER_DATA_DIRECTORY)}[/yellow]"
|
|
)
|
|
success_userdata = True
|
|
|
|
console.print()
|