"""Utils."""
import argparse
import os
import random
import re
import shutil
import sys
from contextlib import contextmanager
from datetime import (
datetime,
)
from pathlib import Path
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
import numpy as np
import pandas as pd
import requests
from openbb import obb
from openbb_charting.core.backend import create_backend, get_backend
from openbb_cli.config.constants import AVAILABLE_FLAIRS, ENV_FILE_SETTINGS
from openbb_cli.session import Session
from openbb_core.app.model.charts.charting_settings import ChartingSettings
from pytz import all_timezones, timezone
from rich.table import Table
if TYPE_CHECKING:
from openbb_charting.core.openbb_figure import OpenBBFigure
# pylint: disable=R1702,R0912
# pylint: disable=too-many-statements,no-member,too-many-branches,C0302
def remove_file(path: Path) -> bool:
"""Remove path.
Parameters
----------
path : Path
The file path.
Returns
-------
bool
The status of the removal.
"""
# TODO: Check why module level import leads to circular import.
try:
if os.path.isfile(path):
os.remove(path)
elif os.path.isdir(path):
shutil.rmtree(path)
return True
except Exception:
Session().console.print(
f"\n[bold red]Failed to remove {path}"
"\nPlease delete this manually![/bold red]"
)
return False
def print_goodbye():
"""Print a goodbye message when quitting the terminal."""
# LEGACY GOODBYE MESSAGES - You'll live in our hearts forever.
# "An informed ape, is a strong ape."
# "Remember that stonks only go up."
# "Diamond hands."
# "Apes together strong."
# "This is our way."
# "Keep the spacesuit ape, we haven't reached the moon yet."
# "I am not a cat. I'm an ape."
# "We like the terminal."
# "...when offered a flight to the moon, nobody asks about what seat."
text = """
[param]Thank you for using the OpenBB Platform CLI and being part of this journey.[/param]
We hope you'll find the new OpenBB Platform CLI a valuable tool.
To stay tuned, sign up for our newsletter: [cmds]https://openbb.co/newsletter.[/]
Please feel free to check out our other products:
[bold]OpenBB Terminal Pro[/]: [cmds]https://openbb.co/products/pro[/cmds]
[bold]OpenBB Platform:[/] [cmds]https://openbb.co/products/platform[/cmds]
[bold]OpenBB Bot[/]: [cmds]https://openbb.co/products/bot[/cmds]
"""
Session().console.print(text)
def print_guest_block_msg():
"""Block guest users from using the cli."""
if Session().is_local():
Session().console.print(
"[info]You are currently logged as a guest.[/info]\n"
"[info]Login to use this feature.[/info]\n\n"
"[info]If you don't have an account, you can create one here: [/info]"
f"[cmds]{Session().settings.HUB_URL + '/register'}\n[/cmds]"
)
def bootup():
"""Bootup the cli."""
if sys.platform == "win32":
# Enable VT100 Escape Sequence for WINDOWS 10 Ver. 1607
os.system("") # nosec # noqa: S605,S607
try:
if os.name == "nt":
# pylint: disable=E1101
sys.stdin.reconfigure(encoding="utf-8") # type: ignore
# pylint: disable=E1101
sys.stdout.reconfigure(encoding="utf-8") # type: ignore
except Exception as e:
Session().console.print