mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-02 07:23:25 +00:00
* feat: experimenting tables with react * feat: adding new interactive tables * feat: adding more table features * small changes * update * Update backend.py * Update backend.py * fix: dark mode? * feat: lot of table improvements * fix: my b * fix: load only when prod * feat: naive detect links and dates * handle index and column names * increased min width * codespell * mypy, pylint * fix: added new chart, export, etc * testing * updates * fix : add PLOT_OPEN_EXPORT, USE_INTERACTIVE_DF to user dataclass * bump pywry version, readd removed `plots_backend().start()` * req files * Update unit-test.yml * Update unit-test.yml * Update unit-test.yml * updates * fixing some date things * update table * fix formatting with timezones * fixing some long prints and tables * Mickey Mouse Co-authored-by: teh_coderer <tehcoderer@users.noreply.github.com> Co-authored-by: jose-donato <jose-donato@users.noreply.github.com> * fix: ?!?!? * adding limit arg to all print_rich_table * tests * lint * simple by Default on interactive charts * playing with some css (thks jose) * Fix #4426 * Edit some structure * fix sdk generation * Update backend.py * fa menu tested and working * fix #4460 * fix #4460 drop indices * update tests * update tests * Update helper_funcs.py * tests * Update unit-test.yml * Update etf.ipynb --------- Co-authored-by: teh_coderer <me@tehcoderer.com> Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com> Co-authored-by: teh_coderer <tehcoderer@users.noreply.github.com> Co-authored-by: jose-donato <jose-donato@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
82 lines
1.8 KiB
Python
82 lines
1.8 KiB
Python
"""CSIMarket Model"""
|
|
__docformat__ = "numpy"
|
|
|
|
import logging
|
|
|
|
import pandas as pd
|
|
|
|
from openbb_terminal.decorators import log_start_end
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def clean_table(df: pd.DataFrame) -> pd.DataFrame:
|
|
"""Clean up the table from CSIMarket
|
|
|
|
Parameters
|
|
----------
|
|
df: pd.DataFrame
|
|
Dataframe to clean
|
|
|
|
Returns
|
|
-------
|
|
df: pd.DataFrame
|
|
Cleaned dataframe
|
|
"""
|
|
if df.empty:
|
|
return df
|
|
if "TICKER" in df.columns:
|
|
df = df.set_index("TICKER")
|
|
df.columns = [x.title() for x in df.columns]
|
|
if "Company Name.1" in df.columns:
|
|
df = df.drop("Company Name.1", axis=1)
|
|
if "SUBTOTAL" in df.index:
|
|
df = df.drop("SUBTOTAL", axis=0)
|
|
if "Revenue" in df.columns:
|
|
df = df.sort_values("Revenue", ascending=False)
|
|
df = df[df.index.notnull()]
|
|
return df
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_suppliers(symbol: str) -> pd.DataFrame:
|
|
"""Get suppliers from ticker provided. [Source: CSIMarket]
|
|
|
|
Parameters
|
|
----------
|
|
symbol: str
|
|
Ticker to select suppliers from
|
|
|
|
Returns
|
|
-------
|
|
pd.DataFrame
|
|
A dataframe of suppliers
|
|
"""
|
|
url = f"https://csimarket.com/stocks/competition2.php?supply&code={symbol.upper()}"
|
|
dfs = pd.read_html(url, header=0)
|
|
df = dfs[10]
|
|
df = clean_table(df)
|
|
return df
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_customers(symbol: str) -> pd.DataFrame:
|
|
"""Print customers from ticker provided
|
|
|
|
Parameters
|
|
----------
|
|
symbol: str
|
|
Ticker to select customers from
|
|
|
|
Returns
|
|
-------
|
|
pd.DataFrame
|
|
A dataframe of suppliers
|
|
"""
|
|
url = f"https://csimarket.com/stocks/custexNO.php?markets&code={symbol.upper()}"
|
|
dfs = pd.read_html(url, header=0)
|
|
df = dfs[9]
|
|
df = clean_table(df)
|
|
|
|
return df
|