mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-12-01 05:33:37 +00:00
@@ -114,20 +114,25 @@ class CreateExcelFA:
|
||||
raise ValueError("The ticker given is not in the stock analysis website.")
|
||||
soup = BeautifulSoup(r.content, "html.parser")
|
||||
|
||||
table = soup.find(
|
||||
"table", attrs={"class": re.compile("^FinancialTable_table_financial__.*")}
|
||||
)
|
||||
table = soup.find("table", attrs={"class": re.compile("fintbl")})
|
||||
head = table.find("thead")
|
||||
columns = head.find_all("th")
|
||||
|
||||
if self.years == []:
|
||||
self.years = [x.get_text().strip() for x in columns]
|
||||
self.years = [
|
||||
x.get_text().strip() for x in columns if "-" not in x.get_text().strip()
|
||||
]
|
||||
self.len_data = len(self.years) - 1
|
||||
|
||||
if self.rounding == 0:
|
||||
phrase = soup.find(
|
||||
"div", attrs={"class": "text-sm pb-1 text-gray-600"}
|
||||
).get_text()
|
||||
phrase = (
|
||||
soup.find(
|
||||
"div", attrs={"class": "text-sm text-gray-600 block lg:hidden"}
|
||||
)
|
||||
.get_text()
|
||||
.lower()
|
||||
)
|
||||
|
||||
if "thousand" in phrase:
|
||||
self.rounding = 1_000
|
||||
elif "millions" in phrase:
|
||||
@@ -151,6 +156,7 @@ class CreateExcelFA:
|
||||
]
|
||||
|
||||
df = pd.DataFrame(data=all_data)
|
||||
df = df.loc[:, ~(df == "Upgrade").any()]
|
||||
df = df.set_index(0)
|
||||
n = df.shape[1] - self.len_data
|
||||
if n > 0:
|
||||
@@ -199,6 +205,7 @@ class CreateExcelFA:
|
||||
rowI += 1
|
||||
|
||||
column = 1
|
||||
|
||||
for key, value in df.iteritems():
|
||||
rowI = row
|
||||
if header:
|
||||
@@ -1268,16 +1275,22 @@ class CreateExcelFA:
|
||||
i = 0
|
||||
new_list = []
|
||||
while i < 3 and sisters:
|
||||
try:
|
||||
sister_ret = [
|
||||
self.get_sister_data(x, sisters[0]) for x in ["BS", "IS", "CF"]
|
||||
]
|
||||
print(sister_ret)
|
||||
blank = [x.empty for x in sister_ret]
|
||||
if True in blank:
|
||||
sisters.pop(0)
|
||||
else:
|
||||
vals = [
|
||||
sisters[0],
|
||||
[self.get_sister_data(x, sisters[0]) for x in ["BS", "IS", "CF"]],
|
||||
sister_ret,
|
||||
]
|
||||
new_list.append(vals)
|
||||
i += 1
|
||||
sisters.pop(0)
|
||||
except ValueError:
|
||||
sisters.pop(0)
|
||||
|
||||
self.sister_data = new_list
|
||||
|
||||
def get_sister_data(self, statement: str, ticker: str) -> pd.DataFrame:
|
||||
@@ -1295,26 +1308,29 @@ class CreateExcelFA:
|
||||
|
||||
if "404 - Page Not Found" in r.text:
|
||||
# TODO: add better handling
|
||||
print("Unable to find requested sister ticker for ration analysis")
|
||||
raise ValueError("The ticker given is not in the stock analysis website.")
|
||||
return pd.DataFrame()
|
||||
soup = BeautifulSoup(r.content, "html.parser")
|
||||
|
||||
table = soup.find(
|
||||
"table", attrs={"class": re.compile("^FinancialTable_table_financial__.*")}
|
||||
)
|
||||
table = soup.find("table", attrs={"class": re.compile("fintbl")})
|
||||
head = table.find("thead")
|
||||
if head is None:
|
||||
raise ValueError("Incorrect website format")
|
||||
return pd.DataFrame()
|
||||
columns = head.find_all("th")
|
||||
|
||||
if self.years == []:
|
||||
self.years = [x.get_text().strip() for x in columns]
|
||||
self.years = [
|
||||
x.get_text().strip() for x in columns if "-" not in x.get_text().strip()
|
||||
]
|
||||
self.len_data = len(self.years) - 1
|
||||
|
||||
if self.rounding == 0:
|
||||
phrase = soup.find(
|
||||
"div", attrs={"class": "text-sm pb-1 text-gray-600"}
|
||||
).get_text()
|
||||
phrase = (
|
||||
soup.find(
|
||||
"div", attrs={"class": "text-sm text-gray-600 block lg:hidden"}
|
||||
)
|
||||
.get_text()
|
||||
.lower()
|
||||
)
|
||||
if "thousand" in phrase:
|
||||
self.rounding = 1_000
|
||||
elif "millions" in phrase:
|
||||
@@ -1322,9 +1338,7 @@ class CreateExcelFA:
|
||||
elif "billions" in phrase:
|
||||
self.rounding = 1_000_000_000
|
||||
else:
|
||||
raise ValueError(
|
||||
"Stock Analysis did not specify a proper rounding amount"
|
||||
)
|
||||
return pd.DataFrame
|
||||
|
||||
body = table.find("tbody")
|
||||
rows = body.find_all("tr")
|
||||
@@ -1332,6 +1346,7 @@ class CreateExcelFA:
|
||||
all_data = [[x.get_text().strip() for x in y.find_all("td")] for y in rows]
|
||||
|
||||
df = pd.DataFrame(data=all_data)
|
||||
df = df.loc[:, ~(df == "Upgrade").any()]
|
||||
df = df.set_index(0)
|
||||
n = df.shape[1] - self.len_data
|
||||
if n > 0:
|
||||
@@ -1354,7 +1369,7 @@ class CreateExcelFA:
|
||||
if vals[0] in df.index:
|
||||
blank_list = ["0" for _ in df.loc[vals[0]].to_list()]
|
||||
else:
|
||||
raise ValueError("Dataframe does not have key information.")
|
||||
return pd.DataFrame()
|
||||
for i, _ in enumerate(vals[1][1:]):
|
||||
df = dcf_model.insert_row(vals[1][i + 1], vals[1][i], df, blank_list)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user