mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-28 12:13:11 +00:00
Fix hotpenny data acquisition (#725)
* Fix hotpenny data acquisition * fix pylint issues
This commit is contained in:
@@ -562,33 +562,21 @@ Quandl/Stockgrid:
|
||||
dest="stockgrid",
|
||||
help="Source of short interest volume",
|
||||
)
|
||||
if "quandl" in other_args:
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--nyse",
|
||||
action="store_true",
|
||||
default=False,
|
||||
dest="b_nyse",
|
||||
help="Data from NYSE flag. Otherwise comes from NASDAQ.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-d",
|
||||
"--days",
|
||||
action="store",
|
||||
dest="n_days",
|
||||
type=check_positive,
|
||||
default=10 if "-r" in other_args else 120,
|
||||
help="Number of latest days to print data.",
|
||||
)
|
||||
else:
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--number",
|
||||
help="Number of last open market days to show",
|
||||
type=check_positive,
|
||||
default=10 if "-r" in other_args else 120,
|
||||
dest="num",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--nyse",
|
||||
action="store_true",
|
||||
default=False,
|
||||
dest="b_nyse",
|
||||
help="ONLY QUANDL SOURCE. Data from NYSE flag. Otherwise comes from NASDAQ.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--number",
|
||||
help="Number of last open market days to show",
|
||||
type=check_positive,
|
||||
default=10 if "-r" in other_args else 120,
|
||||
dest="num",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-r",
|
||||
action="store_true",
|
||||
@@ -615,7 +603,7 @@ Quandl/Stockgrid:
|
||||
quandl_view.short_interest(
|
||||
ticker=self.ticker,
|
||||
nyse=ns_parser.b_nyse,
|
||||
days=ns_parser.n_days,
|
||||
days=ns_parser.num,
|
||||
raw=ns_parser.raw,
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@@ -67,46 +67,37 @@ def get_today_hot_penny_stocks() -> DataFrame:
|
||||
|
||||
text_soup_penny_stock_stocks = BeautifulSoup(
|
||||
requests.get(
|
||||
url_penny_stock_stocks, headers={"User-Agent": get_user_agent()}
|
||||
url_penny_stock_stocks,
|
||||
headers={
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.10; rv:86.1) Gecko/20100101 Firefox/86.1"
|
||||
},
|
||||
).text,
|
||||
"lxml",
|
||||
)
|
||||
|
||||
a_penny_stock_header = []
|
||||
a_penny_stock_header = list()
|
||||
for penny_stock_header in text_soup_penny_stock_stocks.findAll(
|
||||
"td", {"class": "tblhdr"}
|
||||
):
|
||||
a_penny_stock_header.append(penny_stock_header.text)
|
||||
|
||||
df_penny = pd.DataFrame(columns=a_penny_stock_header)
|
||||
l_stocks = list()
|
||||
for penny_stock in text_soup_penny_stock_stocks.find_all("a", href=True):
|
||||
if penny_stock.text:
|
||||
l_stocks.append(penny_stock.text)
|
||||
|
||||
first_penny = []
|
||||
for idx, penny_stock_header in enumerate(text_soup_penny_stock_stocks.findAll("a")):
|
||||
if idx == 0:
|
||||
continue
|
||||
if idx > 1:
|
||||
break
|
||||
first_penny.append(penny_stock_header.text)
|
||||
|
||||
for idx, first_penny_stock in enumerate(
|
||||
text_soup_penny_stock_stocks.findAll("td", {"align": "right"})
|
||||
):
|
||||
first_penny.append(first_penny_stock.text)
|
||||
if idx > 3:
|
||||
break
|
||||
|
||||
df_penny.loc[0] = first_penny
|
||||
|
||||
a_penny_stock = []
|
||||
penny_idx = 1
|
||||
for idx, penny_stock in enumerate(
|
||||
text_soup_penny_stock_stocks.findAll("td", {"class": "tdi"})
|
||||
):
|
||||
a_penny_stock = list()
|
||||
penny_idx = 0
|
||||
d_stocks = {}
|
||||
for penny_stock in text_soup_penny_stock_stocks.findAll("td", {"align": "right"}):
|
||||
a_penny_stock.append(penny_stock.text)
|
||||
|
||||
if (idx + 1) % 6 == 0:
|
||||
df_penny.loc[penny_idx] = a_penny_stock
|
||||
if len(a_penny_stock) == 5:
|
||||
d_stocks[l_stocks[penny_idx]] = a_penny_stock
|
||||
penny_idx += 1
|
||||
a_penny_stock = []
|
||||
a_penny_stock = list()
|
||||
|
||||
df_penny = pd.DataFrame.from_dict(d_stocks).T
|
||||
df_penny.columns = a_penny_stock_header[1:]
|
||||
|
||||
return df_penny
|
||||
|
||||
@@ -57,7 +57,7 @@ def hot_penny_stocks(num: int, export: str):
|
||||
df_penny_stocks.head(num),
|
||||
headers=df_penny_stocks.columns,
|
||||
floatfmt=".2f",
|
||||
showindex=False,
|
||||
showindex=True,
|
||||
tablefmt="fancy_grid",
|
||||
),
|
||||
"\n",
|
||||
|
||||
Reference in New Issue
Block a user