Skip to content

Commit

Permalink
prevent key error
Browse files Browse the repository at this point in the history
  • Loading branch information
deeleeramone committed May 23, 2024
1 parent aaf65cc commit 40347ea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,45 +150,41 @@ def transform_data(
if period_type == "quarterly"
else "FY"
)
eps_estimates["number_of_analysts"] = seek_object[
"eps_normalized_num_of_estimates"
][str(i)][0].get("dataitemvalue")
num_estimates = seek_object["revenue_num_of_estimates"].get(str(i))
if not num_estimates:
continue
eps_estimates["number_of_analysts"] = num_estimates[0].get(
"dataitemvalue"
)
actual = seek_object["eps_normalized_actual"].get(str(i))
gaap_actual = seek_object["eps_gaap_actual"].get(str(i))
if actual:
eps_estimates["normalized_actual"] = actual[0].get("dataitemvalue")
gaap_actual = seek_object["eps_gaap_actual"].get(str(i))
if gaap_actual:
eps_estimates["gaap_actual"] = gaap_actual[0].get("dataitemvalue")
low = seek_object["eps_normalized_consensus_low"][str(i)][0].get(
"dataitemvalue"
)
low = seek_object["eps_normalized_consensus_low"].get(str(i))
if low:
eps_estimates["low_estimate"] = low
gaap_low = seek_object["eps_gaap_consensus_low"][str(i)][0].get(
"dataitemvalue"
)
eps_estimates["low_estimate"] = low[0].get("dataitemvalue")
gaap_low = seek_object["eps_gaap_consensus_low"].get(str(i))
if gaap_low:
eps_estimates["low_estimate_gaap"] = gaap_low
high = seek_object["eps_normalized_consensus_high"][str(i)][0].get(
"dataitemvalue"
)
eps_estimates["low_estimate_gaap"] = gaap_low[0].get(
"dataitemvalue"
)
high = seek_object["eps_normalized_consensus_high"].get(str(i))
if high:
eps_estimates["high_estimate"] = high
gaap_high = seek_object["eps_gaap_consensus_high"][str(i)][0].get(
"dataitemvalue"
)
eps_estimates["high_estimate"] = high[0].get("dataitemvalue")
gaap_high = seek_object["eps_gaap_consensus_high"].get(str(i))
if gaap_high:
eps_estimates["high_estimate_gaap"] = gaap_high
mean = seek_object["eps_normalized_consensus_mean"][str(i)][0].get(
"dataitemvalue"
)
eps_estimates["high_estimate_gaap"] = gaap_high[0].get(
"dataitemvalue"
)
mean = seek_object["eps_normalized_consensus_mean"].get(str(i))
if mean:
mean = mean[0].get("dataitemvalue")
eps_estimates["mean"] = mean
gaap_mean = seek_object["eps_gaap_consensus_mean"][str(i)][0].get(
"dataitemvalue"
)
gaap_mean = seek_object["eps_gaap_consensus_mean"].get(str(i))
if gaap_mean:
eps_estimates["mean_gaap"] = gaap_mean
eps_estimates["mean_gaap"] = gaap_mean[0].get("dataitemvalue")
# Calculate the estimated growth percent.
this = float(mean) if mean else None
prev = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def aextract_data(
"estimates_data_items": "revenue_actual,revenue_consensus_low,revenue_consensus_mean,"
"revenue_consensus_high,revenue_num_of_estimates",
"period_type": fp,
"relative_periods": "-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11",
"relative_periods": "-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12",
}
ids = {ticker: await get_seekingalpha_id(ticker) for ticker in tickers}
querystring["ticker_ids"] = (",").join(list(ids.values()))
Expand Down Expand Up @@ -111,7 +111,7 @@ def transform_data(
warn(f"Symbol Error: No data found for, {ticker}")
seek_object = estimates.get(sa_id)
items = len(seek_object["revenue_num_of_estimates"])
for i in range(0, items - 3):
for i in range(0, items - 4):
rev_estimates: Dict = {}
rev_estimates["symbol"] = ticker
period = seek_object["revenue_num_of_estimates"][str(i)][0].get(
Expand All @@ -132,13 +132,15 @@ def transform_data(
if period_type == "quarterly"
else "FY"
)
rev_estimates["number_of_analysts"] = seek_object[
"revenue_num_of_estimates"
][str(i)][0].get("dataitemvalue")
mean = seek_object["revenue_consensus_mean"][str(i)][0].get(
num_estimates = seek_object["revenue_num_of_estimates"].get(str(i))
if not num_estimates:
continue
rev_estimates["number_of_analysts"] = num_estimates[0].get(
"dataitemvalue"
)
mean = seek_object["revenue_consensus_mean"].get(str(i))
if mean:
mean = mean[0].get("dataitemvalue")
rev_estimates["mean"] = int(float(mean))
actual = (
seek_object["revenue_actual"][str(i)][0].get("dataitemvalue")
Expand All @@ -147,15 +149,13 @@ def transform_data(
)
if actual:
rev_estimates["actual"] = int(float(actual))
low = seek_object["revenue_consensus_low"][str(i)][0].get(
"dataitemvalue"
)
low = seek_object["revenue_consensus_low"].get(str(i))
if low:
low = low[0].get("dataitemvalue")
rev_estimates["low_estimate"] = int(float(low))
high = seek_object["revenue_consensus_high"][str(i)][0].get(
"dataitemvalue"
)
high = seek_object["revenue_consensus_high"].get(str(i))
if high:
high = high[0].get("dataitemvalue")
rev_estimates["high_estimate"] = int(float(high))
# Calculate the estimated growth percent.
this = float(mean) if mean else None
Expand Down

0 comments on commit 40347ea

Please sign in to comment.