remove esg endpoints
This commit is contained in:
parent
7a19524d59
commit
56910ab841
@ -100,17 +100,17 @@ class StockDatabase:
|
|||||||
urls = [
|
urls = [
|
||||||
f"https://financialmodelingprep.com/api/v3/profile/{symbol}?apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/profile/{symbol}?apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v3/quote/{symbol}?apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/quote/{symbol}?apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v3/income-statement/{symbol}?period=quarter&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/income-statement/{symbol}?period=annual&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v3/income-statement-growth/{symbol}?period=quarter&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/income-statement-growth/{symbol}?period=annual&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v4/esg-environmental-social-governance-data-ratings?symbol={symbol}&apikey={api_key}",
|
#f"https://financialmodelingprep.com/api/v4/esg-environmental-social-governance-data-ratings?symbol={symbol}&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v4/esg-environmental-social-governance-data?symbol={symbol}&apikey={api_key}",
|
#f"https://financialmodelingprep.com/api/v4/esg-environmental-social-governance-data?symbol={symbol}&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v3/historical-price-full/stock_dividend/{symbol}?limit=400&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/historical-price-full/stock_dividend/{symbol}?limit=400&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v4/historical/employee_count?symbol={symbol}&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v4/historical/employee_count?symbol={symbol}&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v3/balance-sheet-statement/{symbol}?period=quarter&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/balance-sheet-statement/{symbol}?period=annual&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v3/balance-sheet-statement-growth/{symbol}?period=quarter&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/balance-sheet-statement-growth/{symbol}?period=annual&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v3/cash-flow-statement/{symbol}?period=quarter&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/cash-flow-statement/{symbol}?period=annual&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v3/cash-flow-statement-growth/{symbol}?period=quarter&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/cash-flow-statement-growth/{symbol}?period=annual&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v3/ratios/{symbol}?period=quarter&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/ratios/{symbol}?period=annual&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v3/historical-price-full/stock_split/{symbol}?apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v3/historical-price-full/stock_split/{symbol}?apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v4/stock_peers?symbol={symbol}&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v4/stock_peers?symbol={symbol}&apikey={api_key}",
|
||||||
f"https://financialmodelingprep.com/api/v4/institutional-ownership/institutional-holders/symbol-ownership-percent?date={quarter_date}&symbol={symbol}&page=0&apikey={api_key}",
|
f"https://financialmodelingprep.com/api/v4/institutional-ownership/institutional-holders/symbol-ownership-percent?date={quarter_date}&symbol={symbol}&page=0&apikey={api_key}",
|
||||||
@ -124,7 +124,7 @@ class StockDatabase:
|
|||||||
|
|
||||||
# Check if 'income' and 'income_growth' data already exist for the symbol
|
# Check if 'income' and 'income_growth' data already exist for the symbol
|
||||||
try:
|
try:
|
||||||
self.cursor.execute("SELECT income, income_growth, balance, balance_growth, cashflow, cashflow_growth, ratios, stock_peers, esg_data, esg_ratings FROM stocks WHERE symbol = ?", (symbol,))
|
self.cursor.execute("SELECT income, income_growth, balance, balance_growth, cashflow, cashflow_growth, ratios, stock_peersFROM stocks WHERE symbol = ?", (symbol,))
|
||||||
existing_data = self.cursor.fetchone()
|
existing_data = self.cursor.fetchone()
|
||||||
income_exists = existing_data and existing_data[0] is not None
|
income_exists = existing_data and existing_data[0] is not None
|
||||||
income_growth_exists = existing_data and existing_data[1] is not None
|
income_growth_exists = existing_data and existing_data[1] is not None
|
||||||
@ -176,12 +176,7 @@ class StockDatabase:
|
|||||||
elif 'stock_peers/' in url and stock_peers_exists:
|
elif 'stock_peers/' in url and stock_peers_exists:
|
||||||
print(f"Skipping stock_peers for {symbol} as it already exists.")
|
print(f"Skipping stock_peers for {symbol} as it already exists.")
|
||||||
continue
|
continue
|
||||||
elif 'esg-environmental-social-governance-data' in url and esg_data_exists:
|
|
||||||
print(f"Skipping esg_data for {symbol} as it already exists.")
|
|
||||||
continue
|
|
||||||
elif 'esg-environmental-social-governance-data-ratings?' in url and esg_ratings_exists:
|
|
||||||
print(f"Skipping esg_ratings for {symbol} as it already exists.")
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
async with session.get(url) as response:
|
async with session.get(url) as response:
|
||||||
@ -284,16 +279,7 @@ class StockDatabase:
|
|||||||
elif isinstance(parsed_data, list) and "cash-flow-statement-growth/" in url:
|
elif isinstance(parsed_data, list) and "cash-flow-statement-growth/" in url:
|
||||||
# Handle list response, save as JSON object
|
# Handle list response, save as JSON object
|
||||||
fundamental_data['cashflow_growth'] = ujson.dumps(parsed_data)
|
fundamental_data['cashflow_growth'] = ujson.dumps(parsed_data)
|
||||||
elif isinstance(parsed_data, list) and "esg-environmental-social-governance-data?" in url:
|
|
||||||
# Handle list response, save as JSON object
|
|
||||||
fundamental_data['esg_data'] = ujson.dumps(parsed_data[0])
|
|
||||||
data_dict = {'ESGScore': parsed_data[0]['ESGScore']}
|
|
||||||
fundamental_data.update(data_dict)
|
|
||||||
|
|
||||||
elif isinstance(parsed_data, list) and "esg-environmental-social-governance-data-ratings?" in url:
|
|
||||||
# Handle list response, save as JSON object
|
|
||||||
fundamental_data['esg_ratings'] = ujson.dumps(parsed_data[0])
|
|
||||||
|
|
||||||
elif "stock_dividend" in url:
|
elif "stock_dividend" in url:
|
||||||
# Handle list response, save as JSON object
|
# Handle list response, save as JSON object
|
||||||
fundamental_data['stock_dividend'] = ujson.dumps(parsed_data)
|
fundamental_data['stock_dividend'] = ujson.dumps(parsed_data)
|
||||||
|
|||||||
@ -58,16 +58,6 @@ async def get_data(ticker):
|
|||||||
except:
|
except:
|
||||||
forward_pe = None
|
forward_pe = None
|
||||||
|
|
||||||
if data['esg_data'] == None:
|
|
||||||
company_esg_score = {'ESGScore': 'n/a', 'socialScore': 'n/a', 'environmentalScore': 'n/a', 'governanceScore': 'n/a'}
|
|
||||||
company_esg_rating = {'ESGRiskRating': 'n/a', 'industry': 'n/a'}
|
|
||||||
else:
|
|
||||||
company_esg_score = ujson.loads(data['esg_data'])
|
|
||||||
if data['esg_ratings'] == None:
|
|
||||||
company_esg_rating = {'ESGRiskRating': 'n/a', 'industry': 'n/a'}
|
|
||||||
else:
|
|
||||||
company_esg_rating = ujson.loads(data['esg_ratings'])
|
|
||||||
|
|
||||||
if data['stock_split'] == None:
|
if data['stock_split'] == None:
|
||||||
company_stock_split = []
|
company_stock_split = []
|
||||||
else:
|
else:
|
||||||
@ -92,28 +82,12 @@ async def get_data(ticker):
|
|||||||
'previousClose': company_quote['price'], #This is true because I update my db before the market opens hence the price will be the previousClose price.
|
'previousClose': company_quote['price'], #This is true because I update my db before the market opens hence the price will be the previousClose price.
|
||||||
'website': company_profile[0]['website'],
|
'website': company_profile[0]['website'],
|
||||||
'description': company_profile[0]['description'],
|
'description': company_profile[0]['description'],
|
||||||
'esgScore': company_esg_score['ESGScore'],
|
|
||||||
'socialScore': company_esg_score['socialScore'],
|
|
||||||
'environmentalScore': company_esg_score['environmentalScore'],
|
|
||||||
'governanceScore': company_esg_score['governanceScore'],
|
|
||||||
'esgRiskRating': company_esg_rating['ESGRiskRating'],
|
|
||||||
'fullTimeEmployees': company_profile[0]['fullTimeEmployees'],
|
'fullTimeEmployees': company_profile[0]['fullTimeEmployees'],
|
||||||
'stockSplits': company_stock_split,
|
'stockSplits': company_stock_split,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
if data['esg_data'] == None:
|
|
||||||
company_esg_score = {'ESGScore': 'n/a', 'socialScore': 'n/a', 'environmentalScore': 'n/a', 'governanceScore': 'n/a'}
|
|
||||||
company_esg_rating = {'ESGRiskRating': 'n/a', 'industry': 'n/a'}
|
|
||||||
else:
|
|
||||||
company_esg_score = ujson.loads(data['esg_data'])
|
|
||||||
if data['esg_ratings'] == None:
|
|
||||||
company_esg_rating = {'ESGRiskRating': 'n/a', 'industry': 'n/a'}
|
|
||||||
else:
|
|
||||||
company_esg_rating = ujson.loads(data['esg_ratings'])
|
|
||||||
|
|
||||||
|
|
||||||
final_res = {k: v for d in [res_profile] for dict in d for k, v in dict.items()}
|
final_res = {k: v for d in [res_profile] for dict in d for k, v in dict.items()}
|
||||||
|
|
||||||
return final_res
|
return final_res
|
||||||
|
|||||||
@ -56,7 +56,7 @@ async def get_stock_screener(con,symbols):
|
|||||||
|
|
||||||
#Stock Screener Data
|
#Stock Screener Data
|
||||||
|
|
||||||
cursor.execute("SELECT symbol, name, avgVolume, change_1W, change_1M, change_3M, change_6M, change_1Y, change_3Y, sma_50, sma_200, ema_50, ema_200, rsi, atr, stoch_rsi, mfi, cci, priceToSalesRatio, priceToBookRatio, eps, pe, ESGScore, marketCap, revenue, netIncome, grossProfit, costOfRevenue, costAndExpenses, interestIncome, interestExpense, researchAndDevelopmentExpenses, ebitda, operatingExpenses, operatingIncome, growthRevenue, growthNetIncome, growthGrossProfit, growthCostOfRevenue, growthCostAndExpenses, growthInterestExpense, growthResearchAndDevelopmentExpenses, growthEBITDA, growthEPS, growthOperatingExpenses, growthOperatingIncome, beta FROM stocks WHERE eps IS NOT NULL AND revenue IS NOT NULL AND marketCap IS NOT NULL AND beta IS NOT NULL")
|
cursor.execute("SELECT symbol, name, avgVolume, change_1W, change_1M, change_3M, change_6M, change_1Y, change_3Y, sma_50, sma_200, ema_50, ema_200, rsi, atr, stoch_rsi, mfi, cci, priceToSalesRatio, priceToBookRatio, eps, pe, marketCap, revenue, netIncome, grossProfit, costOfRevenue, costAndExpenses, interestIncome, interestExpense, researchAndDevelopmentExpenses, ebitda, operatingExpenses, operatingIncome, growthRevenue, growthNetIncome, growthGrossProfit, growthCostOfRevenue, growthCostAndExpenses, growthInterestExpense, growthResearchAndDevelopmentExpenses, growthEBITDA, growthEPS, growthOperatingExpenses, growthOperatingIncome, beta FROM stocks WHERE eps IS NOT NULL AND revenue IS NOT NULL AND marketCap IS NOT NULL AND beta IS NOT NULL")
|
||||||
raw_data = cursor.fetchall()
|
raw_data = cursor.fetchall()
|
||||||
stock_screener_data = [{
|
stock_screener_data = [{
|
||||||
'symbol': symbol,
|
'symbol': symbol,
|
||||||
@ -81,7 +81,6 @@ async def get_stock_screener(con,symbols):
|
|||||||
'priceToBookRatio': priceToBookRatio,
|
'priceToBookRatio': priceToBookRatio,
|
||||||
'eps': eps,
|
'eps': eps,
|
||||||
'pe': pe,
|
'pe': pe,
|
||||||
'esgScore': ESGScore,
|
|
||||||
'marketCap': marketCap,
|
'marketCap': marketCap,
|
||||||
'revenue': revenue,
|
'revenue': revenue,
|
||||||
'netIncome': netIncome,
|
'netIncome': netIncome,
|
||||||
@ -106,7 +105,7 @@ async def get_stock_screener(con,symbols):
|
|||||||
'growthOperatingExpenses': growthOperatingExpenses,
|
'growthOperatingExpenses': growthOperatingExpenses,
|
||||||
'growthOperatingIncome': growthOperatingIncome,
|
'growthOperatingIncome': growthOperatingIncome,
|
||||||
'beta': beta,
|
'beta': beta,
|
||||||
} for (symbol, name, avgVolume, change_1W, change_1M, change_3M, change_6M, change_1Y, change_3Y, sma_50, sma_200, ema_50, ema_200, rsi, atr, stoch_rsi, mfi, cci, priceToSalesRatio, priceToBookRatio, eps, pe, ESGScore, marketCap, revenue, netIncome, grossProfit,costOfRevenue, costAndExpenses, interestIncome, interestExpense, researchAndDevelopmentExpenses, ebitda, operatingExpenses, operatingIncome, growthRevenue, growthNetIncome, growthGrossProfit, growthCostOfRevenue, growthCostAndExpenses, growthInterestExpense, growthResearchAndDevelopmentExpenses, growthEBITDA, growthEPS, growthOperatingExpenses, growthOperatingIncome, beta) in raw_data]
|
} for (symbol, name, avgVolume, change_1W, change_1M, change_3M, change_6M, change_1Y, change_3Y, sma_50, sma_200, ema_50, ema_200, rsi, atr, stoch_rsi, mfi, cci, priceToSalesRatio, priceToBookRatio, eps, pe, marketCap, revenue, netIncome, grossProfit,costOfRevenue, costAndExpenses, interestIncome, interestExpense, researchAndDevelopmentExpenses, ebitda, operatingExpenses, operatingIncome, growthRevenue, growthNetIncome, growthGrossProfit, growthCostOfRevenue, growthCostAndExpenses, growthInterestExpense, growthResearchAndDevelopmentExpenses, growthEBITDA, growthEPS, growthOperatingExpenses, growthOperatingIncome, beta) in raw_data]
|
||||||
|
|
||||||
stock_screener_data = [{k: round(v, 2) if isinstance(v, (int, float)) else v for k, v in entry.items()} for entry in stock_screener_data]
|
stock_screener_data = [{k: round(v, 2) if isinstance(v, (int, float)) else v for k, v in entry.items()} for entry in stock_screener_data]
|
||||||
|
|
||||||
@ -203,6 +202,9 @@ async def get_stock_screener(con,symbols):
|
|||||||
item['debtEquityRatio'] = round(float(res['debtEquityRatio']),2)
|
item['debtEquityRatio'] = round(float(res['debtEquityRatio']),2)
|
||||||
item['quickRatio'] = round(float(res['quickRatio']),2)
|
item['quickRatio'] = round(float(res['quickRatio']),2)
|
||||||
item['currentRatio'] = round(float(res['currentRatio']),2)
|
item['currentRatio'] = round(float(res['currentRatio']),2)
|
||||||
|
item['freeCashFlowPerShare'] = round(float(res['freeCashFlowPerShare']),2)
|
||||||
|
item['cashPerShare'] = round(float(res['cashPerShare']),2)
|
||||||
|
item['priceToFreeCashFlowsRatio'] = round(float(res['priceToFreeCashFlowsRatio']),2)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
item['returnOnAssets'] = None
|
item['returnOnAssets'] = None
|
||||||
@ -211,6 +213,9 @@ async def get_stock_screener(con,symbols):
|
|||||||
item['debtEquityRatio'] = None
|
item['debtEquityRatio'] = None
|
||||||
item['quickRatio'] = None
|
item['quickRatio'] = None
|
||||||
item['currentRatio'] = None
|
item['currentRatio'] = None
|
||||||
|
item['freeCashFlowPerShare'] = None
|
||||||
|
item['cashPerShare'] = None
|
||||||
|
item['priceToFreeCashFlowsRatio'] = None
|
||||||
|
|
||||||
|
|
||||||
return stock_screener_data
|
return stock_screener_data
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user