mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-13 12:51:49 +00:00
Fix presets being loaded from relative path
This commit is contained in:
@@ -5,9 +5,8 @@ import argparse
|
||||
from typing import List
|
||||
import os
|
||||
import configparser
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
from gamestonk_terminal.papermill import due_diligence_view
|
||||
import pandas as pd
|
||||
from finvizfinance.screener import (
|
||||
technical,
|
||||
overview,
|
||||
@@ -16,11 +15,14 @@ from finvizfinance.screener import (
|
||||
ownership,
|
||||
performance,
|
||||
)
|
||||
from gamestonk_terminal.papermill import due_diligence_view
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
check_positive,
|
||||
)
|
||||
|
||||
presets_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "presets/")
|
||||
|
||||
d_signals = {
|
||||
"top_gainers": "Top Gainers",
|
||||
"top_losers": "Top Losers",
|
||||
@@ -83,7 +85,7 @@ def get_screener_data(
|
||||
"""
|
||||
preset_filter = configparser.RawConfigParser()
|
||||
preset_filter.optionxform = str # type: ignore
|
||||
preset_filter.read("gamestonk_terminal/screener/presets/" + preset_loaded + ".ini")
|
||||
preset_filter.read(presets_path + preset_loaded + ".ini")
|
||||
|
||||
d_general = preset_filter["General"]
|
||||
d_filters = {
|
||||
@@ -137,7 +139,7 @@ def get_screener_data(
|
||||
return df_screen
|
||||
|
||||
|
||||
def screener(other_args: List[str], loaded_preset: str, data_type: str):
|
||||
def screener(other_args: List[str], loaded_preset: str, data_type: str) -> List[str]:
|
||||
"""Screener
|
||||
|
||||
Parameters
|
||||
@@ -148,6 +150,11 @@ def screener(other_args: List[str], loaded_preset: str, data_type: str):
|
||||
Loaded preset filter
|
||||
data_type : str
|
||||
Data type string between: overview, valuation, financial, ownership, performance, technical
|
||||
|
||||
Returns
|
||||
-------
|
||||
List[str]
|
||||
List of stocks that meet preset criteria
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
@@ -169,7 +176,7 @@ def screener(other_args: List[str], loaded_preset: str, data_type: str):
|
||||
help="Filter presets",
|
||||
choices=[
|
||||
preset.split(".")[0]
|
||||
for preset in os.listdir("gamestonk_terminal/screener/presets")
|
||||
for preset in os.listdir(presets_path)
|
||||
if preset[-4:] == ".ini"
|
||||
],
|
||||
)
|
||||
@@ -218,7 +225,7 @@ def screener(other_args: List[str], loaded_preset: str, data_type: str):
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
return []
|
||||
|
||||
df_screen = get_screener_data(
|
||||
ns_parser.preset,
|
||||
@@ -245,9 +252,9 @@ def screener(other_args: List[str], loaded_preset: str, data_type: str):
|
||||
ticker = [df_screen.iat[i, 0]]
|
||||
due_diligence_view.due_diligence(ticker, show=False)
|
||||
return list(df_screen["Ticker"].values)
|
||||
else:
|
||||
print("")
|
||||
return []
|
||||
|
||||
print("")
|
||||
return []
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@@ -6,10 +6,10 @@ import argparse
|
||||
import configparser
|
||||
from typing import List
|
||||
import matplotlib.pyplot as plt
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal.helper_funcs import get_flair
|
||||
from gamestonk_terminal.menu import session
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
)
|
||||
@@ -17,6 +17,8 @@ from gamestonk_terminal.screener import finviz_view
|
||||
from gamestonk_terminal.screener import yahoo_finance_view
|
||||
from gamestonk_terminal.portfolio_optimization import po_controller
|
||||
|
||||
presets_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "presets/")
|
||||
|
||||
|
||||
class ScreenerController:
|
||||
"""Screener Controller class"""
|
||||
@@ -49,7 +51,6 @@ class ScreenerController:
|
||||
choices=self.CHOICES,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
@@ -97,7 +98,7 @@ class ScreenerController:
|
||||
default="",
|
||||
choices=[
|
||||
preset.split(".")[0]
|
||||
for preset in os.listdir("gamestonk_terminal/screener/presets")
|
||||
for preset in os.listdir(presets_path)
|
||||
if preset[-4:] == ".ini"
|
||||
],
|
||||
)
|
||||
@@ -113,9 +114,7 @@ class ScreenerController:
|
||||
if ns_parser.preset:
|
||||
preset_filter = configparser.RawConfigParser()
|
||||
preset_filter.optionxform = str # type: ignore
|
||||
preset_filter.read(
|
||||
"gamestonk_terminal/screener/presets/" + ns_parser.preset + ".ini"
|
||||
)
|
||||
preset_filter.read(presets_path + ns_parser.preset + ".ini")
|
||||
|
||||
filters_headers = ["General", "Descriptive", "Fundamental", "Technical"]
|
||||
|
||||
@@ -133,18 +132,18 @@ class ScreenerController:
|
||||
else:
|
||||
presets = [
|
||||
preset.split(".")[0]
|
||||
for preset in os.listdir("gamestonk_terminal/screener/presets")
|
||||
for preset in os.listdir(presets_path)
|
||||
if preset[-4:] == ".ini"
|
||||
]
|
||||
|
||||
for preset in presets:
|
||||
with open(
|
||||
"gamestonk_terminal/screener/presets/" + preset + ".ini",
|
||||
presets_path + preset + ".ini",
|
||||
encoding="utf8",
|
||||
) as f:
|
||||
description = ""
|
||||
for line in f:
|
||||
if "[General]" == line.strip():
|
||||
if line.strip() == "[General]":
|
||||
break
|
||||
description += line.strip()
|
||||
print(f"\nPRESET: {preset}")
|
||||
@@ -154,7 +153,6 @@ class ScreenerController:
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@staticmethod
|
||||
def set_preset(self, other_args: List[str]):
|
||||
"""Set preset"""
|
||||
parser = argparse.ArgumentParser(
|
||||
@@ -172,7 +170,7 @@ class ScreenerController:
|
||||
help="Filter presets",
|
||||
choices=[
|
||||
preset.split(".")[0]
|
||||
for preset in os.listdir("gamestonk_terminal/screener/presets")
|
||||
for preset in os.listdir(presets_path)
|
||||
if preset[-4:] == ".ini"
|
||||
],
|
||||
)
|
||||
@@ -212,7 +210,7 @@ class ScreenerController:
|
||||
|
||||
def call_help(self, _):
|
||||
"""Process Help command"""
|
||||
self.print_help(self)
|
||||
self.print_help()
|
||||
|
||||
def call_q(self, _):
|
||||
"""Process Q command - quit the menu"""
|
||||
@@ -228,7 +226,7 @@ class ScreenerController:
|
||||
|
||||
def call_set(self, other_args: List[str]):
|
||||
"""Process overview command"""
|
||||
self.set_preset(self, other_args)
|
||||
self.set_preset(other_args)
|
||||
|
||||
def call_historical(self, other_args: List[str]):
|
||||
"""Process historical command"""
|
||||
@@ -264,7 +262,7 @@ class ScreenerController:
|
||||
"""Process signals command"""
|
||||
finviz_view.view_signals(other_args)
|
||||
|
||||
def call_po(self, other_args: List[str]):
|
||||
def call_po(self, _):
|
||||
"""Call the portfolio optimization menu with selected tickers"""
|
||||
return po_controller.menu(self.screen_tickers)
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import os
|
||||
import argparse
|
||||
from typing import List
|
||||
import random
|
||||
from pandas.plotting import register_matplotlib_converters
|
||||
import matplotlib.pyplot as plt
|
||||
import datetime
|
||||
import configparser
|
||||
from pandas.plotting import register_matplotlib_converters
|
||||
import matplotlib.pyplot as plt
|
||||
import yfinance as yf
|
||||
from finvizfinance.screener import ticker
|
||||
from gamestonk_terminal.screener import finviz_view
|
||||
@@ -18,6 +19,8 @@ from gamestonk_terminal.config_plot import PLOT_DPI
|
||||
|
||||
register_matplotlib_converters()
|
||||
|
||||
presets_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "presets/")
|
||||
|
||||
d_candle_types = {
|
||||
"o": "Open",
|
||||
"h": "High",
|
||||
@@ -28,18 +31,12 @@ d_candle_types = {
|
||||
|
||||
|
||||
def check_one_of_ohlca(type_candles: str) -> str:
|
||||
if (
|
||||
type_candles == "o"
|
||||
or type_candles == "h"
|
||||
or type_candles == "l"
|
||||
or type_candles == "c"
|
||||
or type_candles == "a"
|
||||
):
|
||||
if type_candles in ("o", "h", "l", "c", "a"):
|
||||
return type_candles
|
||||
raise argparse.ArgumentTypeError("The type of candles specified is not recognized")
|
||||
|
||||
|
||||
def historical(other_args: List[str], preset_loaded: str):
|
||||
def historical(other_args: List[str], preset_loaded: str) -> List[str]:
|
||||
"""View historical price of stocks that meet preset
|
||||
|
||||
Parameters
|
||||
@@ -48,6 +45,11 @@ def historical(other_args: List[str], preset_loaded: str):
|
||||
Command line arguments to be processed with argparse
|
||||
ticker : str
|
||||
Loaded preset filter
|
||||
|
||||
Returns
|
||||
-------
|
||||
List[str]
|
||||
List of stocks that meet preset criteria
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
@@ -85,13 +87,11 @@ def historical(other_args: List[str], preset_loaded: str):
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
return list()
|
||||
|
||||
preset_filter = configparser.RawConfigParser()
|
||||
preset_filter.optionxform = str # type: ignore
|
||||
preset_filter.read(
|
||||
"gamestonk_terminal/screener/presets/" + preset_loaded + ".ini"
|
||||
)
|
||||
preset_filter.read(presets_path + preset_loaded + ".ini")
|
||||
|
||||
d_general = preset_filter["General"]
|
||||
d_filters = {
|
||||
|
||||
@@ -114,7 +114,9 @@ def main():
|
||||
|
||||
try:
|
||||
if os.name == "nt":
|
||||
# pylint: disable=E1101
|
||||
sys.stdin.reconfigure(encoding="utf-8")
|
||||
# pylint: disable=E1101
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
|
||||
Reference in New Issue
Block a user