Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ins/lip (and others) to show full 100 results on the page #3653

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions openbb_terminal/stocks/insider/openinsider_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,38 +1434,30 @@ def get_insider_types() -> Dict:


@log_start_end(log=logger)
def get_print_insider_data(type_insider: str = "lcb", limit: int = 10):
def get_print_insider_data(type_insider: str = "lcb"):
"""Print insider data

Parameters
----------
type_insider: str
Insider type of data. Available types can be accessed through get_insider_types().
limit: int
Limit of data rows to display

Returns
-------
data : pd.DataFrame
Open insider filtered data
"""
response = requests.get(f"http://openinsider.com/{d_open_insider[type_insider]}")
soup = BeautifulSoup(response.text, "html.parser")
table = soup.find("table", {"class": "tinytable"})

if not table:
console.print("No insider information found", "\n")
response = requests.get(
f"http://openinsider.com/{d_open_insider[type_insider]}",
headers={"User-Agent": "Mozilla/5.0"},
)
df = (
pd.read_html(response.text)[-3]
.drop(columns=["1d", "1w", "1m", "6m"])
.fillna("-")
)
if df.empty:
return pd.DataFrame()

table_rows = table.find_all("tr")

res = []
for tr in table_rows:
td = tr.find_all("td")
row = [tr.text.strip() for tr in td if tr.text.strip()]
res.append(row)

df = pd.DataFrame(res).dropna().head(n=limit)
columns = [
"X",
"Filing Date",
Expand Down Expand Up @@ -1503,5 +1495,4 @@ def get_print_insider_data(type_insider: str = "lcb", limit: int = 10):
df["Insider Name"] = df["Insider Name"].apply(
lambda x: "\n".join(textwrap.wrap(x, width=20)) if isinstance(x, str) else x
)

return df
6 changes: 3 additions & 3 deletions openbb_terminal/stocks/insider/openinsider_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ def print_insider_data(type_insider: str = "lcb", limit: int = 10, export: str =
export: str
Export data format
"""
df = get_print_insider_data(type_insider, limit)
df = get_print_insider_data(type_insider)

if not df.empty:
print_rich_table(
df,
df.head(limit),
headers=[x.title() for x in df.columns],
show_index=False,
title="Insider Data",
Expand All @@ -132,7 +132,7 @@ def print_insider_data(type_insider: str = "lcb", limit: int = 10, export: str =
)

if df.shape[1] == 13:
l_chars = [list(chars) for chars in df["X"].values]
l_chars = [list(chars) for chars in df["X"].values if chars != "-"]
l_uchars = np.unique(list(itertools.chain(*l_chars)))

for char in l_uchars:
Expand Down
Loading