fix empty financials from marketwatch

This commit is contained in:
didier
2021-04-27 23:39:54 +01:00
parent ed113cf958
commit 11308e653e
2 changed files with 16 additions and 3 deletions

View File

@@ -73,6 +73,10 @@ def prepare_df_financials(
a_financials_header.append(financials_header.text.strip("\n").split("\n")[0])
s_header_end_trend = ("5-year trend", "5- qtr trend")[quarter]
if s_header_end_trend not in a_financials_header:
return pd.DataFrame()
df_financials = pd.DataFrame(
columns=a_financials_header[0 : a_financials_header.index(s_header_end_trend)]
)

View File

@@ -73,7 +73,10 @@ def income(other_args: List[str], ticker: str):
pd.set_option("display.max_colwidth", None)
pd.set_option("display.max_rows", None)
print(df_financials.to_string(index=False))
if df_financials.empty:
print("Marketwatch does not yet provide financials for this ticker")
else:
print(df_financials.to_string(index=False))
print("")
except Exception as e:
@@ -155,7 +158,10 @@ def balance(other_args: List[str], ticker: str):
pd.set_option("display.max_colwidth", None)
pd.set_option("display.max_rows", None)
print(df_financials.to_string(index=False))
if df_financials.empty:
print("Marketwatch does not yet provide financials for this ticker")
else:
print(df_financials.to_string(index=False))
print("")
except Exception as e:
@@ -233,7 +239,10 @@ def cash(other_args: List[str], ticker: str):
pd.set_option("display.max_colwidth", None)
pd.set_option("display.max_rows", None)
print(df_financials.to_string(index=False))
if df_financials.empty:
print("Marketwatch does not yet provide financials for this ticker")
else:
print(df_financials.to_string(index=False))
print("")
except Exception as e: