mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-29 04:32:43 +00:00
Update code to reflect new changes to FinanceDatabase
This commit is contained in:
@@ -740,15 +740,14 @@ def get_search_indices(keyword: list, limit: int = 10) -> pd.DataFrame:
|
||||
|
||||
indices = fd.Indices()
|
||||
|
||||
queried_indices = indices.search(
|
||||
short_name=keyword_adjusted, exclude_exchanges=True
|
||||
)
|
||||
queried_indices = indices.search(name=keyword_adjusted, exclude_exchanges=True)
|
||||
queried_indices = pd.concat(
|
||||
[
|
||||
queried_indices,
|
||||
indices.search(index=keyword_adjusted),
|
||||
]
|
||||
)
|
||||
queried_indices = queried_indices.drop_duplicates()
|
||||
|
||||
queried_indices = queried_indices.iloc[:limit]
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import logging
|
||||
from typing import Dict, List
|
||||
|
||||
import financedatabase as fd
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from openbb_terminal.decorators import log_start_end
|
||||
@@ -28,9 +29,12 @@ def get_etfs_by_name(name: str) -> Dict:
|
||||
"""
|
||||
etfs = fd.ETFs()
|
||||
|
||||
data = etfs.search(long_name=name, exclude_exchanges=True)
|
||||
data = etfs.search(name=name, exclude_exchanges=True)
|
||||
data = pd.concat([data, etfs.search(index=name, exclude_exchanges=True)])
|
||||
|
||||
# Ensures that data that's missing values is at the bottom of the DataFrame
|
||||
data = data.iloc[np.argsort(-data.isnull().mul(-1).sum(axis=1))]
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@@ -51,7 +55,12 @@ def get_etfs_by_description(description: str) -> Dict:
|
||||
"""
|
||||
etfs = fd.ETFs()
|
||||
|
||||
return etfs.search(summary=description, exclude_exchanges=True)
|
||||
data = etfs.search(summary=description, exclude_exchanges=True)
|
||||
|
||||
# Ensures that data that's missing values is at the bottom of the DataFrame
|
||||
data = data.iloc[np.argsort(-data.isnull().mul(-1).sum(axis=1))]
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
@@ -71,7 +80,12 @@ def get_etfs_by_category(category: str) -> Dict:
|
||||
"""
|
||||
etfs = fd.ETFs()
|
||||
|
||||
return etfs.select(category=category, exclude_exchanges=True)
|
||||
data = etfs.select(category=category, exclude_exchanges=True)
|
||||
|
||||
# Ensures that data that's missing values is at the bottom of the DataFrame
|
||||
data = data.iloc[np.argsort(-data.isnull().mul(-1).sum(axis=1))]
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
|
||||
@@ -39,7 +39,7 @@ def display_etf_by_name(
|
||||
console.print("No data was found with that name.")
|
||||
return
|
||||
|
||||
table_data = data[["long_name", "family", "category_group", "category"]]
|
||||
table_data = data[["name", "family", "category_group", "category"]]
|
||||
|
||||
print_rich_table(
|
||||
table_data.iloc[:limit],
|
||||
@@ -83,7 +83,7 @@ def display_etf_by_description(
|
||||
console.print("No data was found with that description.")
|
||||
return
|
||||
|
||||
table_data = data[["long_name", "family", "category_group", "category"]]
|
||||
table_data = data[["name", "family", "category_group", "category"]]
|
||||
|
||||
print_rich_table(
|
||||
table_data.iloc[:limit],
|
||||
@@ -127,7 +127,7 @@ def display_etf_by_category(
|
||||
console.print("No data was found on that category.")
|
||||
return
|
||||
|
||||
table_data = data[["long_name", "family", "category_group", "category"]]
|
||||
table_data = data[["name", "family", "category_group", "category"]]
|
||||
|
||||
print_rich_table(
|
||||
table_data.iloc[:limit],
|
||||
|
||||
@@ -7,7 +7,7 @@ import os
|
||||
from datetime import datetime, timedelta
|
||||
from typing import List, Optional
|
||||
|
||||
import pandas as pd
|
||||
import financedatabase as fd
|
||||
import yfinance as yf
|
||||
|
||||
from openbb_terminal import feature_flags as obbff
|
||||
@@ -69,20 +69,11 @@ class StocksController(StockBaseController):
|
||||
FILE_PATH = os.path.join(os.path.dirname(__file__), "README.md")
|
||||
|
||||
try:
|
||||
# This is meant to speed up the loading of the stocks menu
|
||||
database_url = "https://raw.githubusercontent.com/JerBouma/FinanceDatabase/main/Database/Categories"
|
||||
country = pd.read_csv(f"{database_url}/equities_countries.csv", header=None)[
|
||||
0
|
||||
].values.tolist()
|
||||
sector = pd.read_csv(f"{database_url}/equities_sectors.csv", header=None)[
|
||||
0
|
||||
].values.tolist()
|
||||
industry_group = pd.read_csv(
|
||||
f"{database_url}/equities_industry_groups.csv", header=None
|
||||
)[0].values.tolist()
|
||||
industry = pd.read_csv(f"{database_url}/equities_industries.csv", header=None)[
|
||||
0
|
||||
].values.tolist()
|
||||
stocks_options = fd.obtain_options("equities")
|
||||
country = stocks_options["country"].tolist()
|
||||
sector = stocks_options["sector"].tolist()
|
||||
industry_group = stocks_options["industry_group"].tolist()
|
||||
industry = stocks_options["industry"].tolist()
|
||||
except Exception:
|
||||
country, sector, industry_group, industry = {}, {}, {}, {}
|
||||
console.print(
|
||||
|
||||
@@ -155,10 +155,8 @@ def search(
|
||||
equities_database = fd.Equities()
|
||||
|
||||
if query:
|
||||
data = equities_database.search(**kwargs, long_name=query)
|
||||
data = pd.concat(
|
||||
[data, equities_database.search(**kwargs, short_name=query)]
|
||||
)
|
||||
data = equities_database.search(**kwargs, name=query)
|
||||
data = pd.concat([data, equities_database.search(**kwargs, name=query)])
|
||||
data = pd.concat(
|
||||
[data, equities_database.search(**kwargs, index=query.upper())]
|
||||
)
|
||||
@@ -185,8 +183,7 @@ def search(
|
||||
|
||||
df = data[
|
||||
[
|
||||
"long_name",
|
||||
"short_name",
|
||||
"name",
|
||||
"country",
|
||||
"sector",
|
||||
"industry_group",
|
||||
@@ -208,9 +205,6 @@ def search(
|
||||
for x in v:
|
||||
exchange_suffix[x] = k
|
||||
|
||||
with pd.option_context("mode.chained_assignment", None):
|
||||
df["name"] = df["long_name"].combine_first(df["short_name"])
|
||||
|
||||
df = df[["name", "country", "sector", "industry_group", "industry", "exchange"]]
|
||||
|
||||
title = "Companies found"
|
||||
|
||||
Reference in New Issue
Block a user