bugfixing stockdeck
This commit is contained in:
parent
359e9ec719
commit
9287d34e3a
@ -122,63 +122,9 @@ class StockDatabase:
|
||||
|
||||
fundamental_data = {}
|
||||
|
||||
# Check if 'income' and 'income_growth' data already exist for the symbol
|
||||
try:
|
||||
self.cursor.execute("SELECT income, income_growth, balance, balance_growth, cashflow, cashflow_growth, ratios, stock_peers FROM stocks WHERE symbol = ?", (symbol,))
|
||||
existing_data = self.cursor.fetchone()
|
||||
income_exists = existing_data and existing_data[0] is not None
|
||||
income_growth_exists = existing_data and existing_data[1] is not None
|
||||
balance_exists = existing_data and existing_data[0] is not None
|
||||
balance_growth_exists = existing_data and existing_data[1] is not None
|
||||
cashflow_exists = existing_data and existing_data[0] is not None
|
||||
cashflow_growth_exists = existing_data and existing_data[1] is not None
|
||||
ratios_exists = existing_data and existing_data[1] is not None
|
||||
stock_peers_exists = existing_data and existing_data[0] is not None
|
||||
esg_data_exists = existing_data and existing_data[0] is not None
|
||||
esg_ratings_exists = existing_data and existing_data[0] is not None
|
||||
except:
|
||||
income_exists = False
|
||||
income_growth_exists = False
|
||||
balance_exists = False
|
||||
balance_growth_exists = False
|
||||
cashflow_exists = False
|
||||
cashflow_growth_exists = False
|
||||
ratios_exists = False
|
||||
stock_peers_exists = False
|
||||
esg_data_exists = False
|
||||
esg_ratings_exists = False
|
||||
|
||||
for url in urls:
|
||||
|
||||
# Skip the API calls if the data already exists
|
||||
if 'income-statement/' in url and income_exists:
|
||||
print(f"Skipping income-statement for {symbol} as it already exists.")
|
||||
continue
|
||||
elif 'income-statement-growth/' in url and income_growth_exists:
|
||||
print(f"Skipping income-statement-growth for {symbol} as it already exists.")
|
||||
continue
|
||||
elif 'balance-sheet-statement/' in url and balance_exists:
|
||||
print(f"Skipping balance-statement for {symbol} as it already exists.")
|
||||
continue
|
||||
elif 'balance-sheet-statement-growth/' in url and balance_growth_exists:
|
||||
print(f"Skipping balance-statement-growth for {symbol} as it already exists.")
|
||||
continue
|
||||
elif 'cash-flow-statement/' in url and cashflow_exists:
|
||||
print(f"Skipping cashflow-statement for {symbol} as it already exists.")
|
||||
continue
|
||||
elif 'cash-flow-statement-growth/' in url and cashflow_growth_exists:
|
||||
print(f"Skipping cashflow-statement-growth for {symbol} as it already exists.")
|
||||
continue
|
||||
elif '/v3/ratios/' in url and ratios_exists:
|
||||
print(f"Skipping ratios for {symbol} as it already exists.")
|
||||
continue
|
||||
|
||||
elif 'stock_peers/' in url and stock_peers_exists:
|
||||
print(f"Skipping stock_peers for {symbol} as it already exists.")
|
||||
continue
|
||||
|
||||
|
||||
|
||||
async with session.get(url) as response:
|
||||
data = await response.text()
|
||||
parsed_data = get_jsonparsed_data(data)
|
||||
@ -307,7 +253,8 @@ class StockDatabase:
|
||||
elif "analyst-estimates" in url:
|
||||
# Handle list response, save as JSON object
|
||||
fundamental_data['analyst_estimates'] = ujson.dumps(parsed_data)
|
||||
except:
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ def clean_financial_data(self, list1, list2):
|
||||
query_template = """
|
||||
SELECT
|
||||
profile, quote,
|
||||
esg_ratings,esg_data,stock_split
|
||||
stock_split
|
||||
FROM
|
||||
stocks
|
||||
WHERE
|
||||
|
||||
@ -604,7 +604,7 @@ schedule.every(15).minutes.do(run_threaded, run_market_moods).tag('market_moods_
|
||||
#schedule.every(10).minutes.do(run_threaded, run_dark_pool_flow).tag('dark_pool_flow_job')
|
||||
|
||||
schedule.every(2).hours.do(run_threaded, run_fda_calendar).tag('fda_calendar_job')
|
||||
schedule.every(3).hours.do(run_threaded, run_json).tag('json_job')
|
||||
schedule.every(6).hours.do(run_threaded, run_json).tag('json_job')
|
||||
#schedule.every(4).hours.do(run_threaded, run_share_statistics).tag('share_statistics_job')
|
||||
#schedule.every(2).days.at("01:00").do(run_borrowed_share).tag('borrowed_share_job')
|
||||
|
||||
|
||||
@ -136,6 +136,11 @@ def get_financial_statements(item, symbol):
|
||||
item.update(process_financial_data(f"json/financial-statements/income-statement/annual/{symbol}.json", key_income))
|
||||
item.update(process_financial_data(f"json/financial-statements/balance-sheet-statement/annual/{symbol}.json", key_balance_sheet))
|
||||
|
||||
try:
|
||||
item['freeCashFlowMargin'] = (item['freeCashFlow'] / item['revenue']) * 100
|
||||
except:
|
||||
item['freeCashFlowMargin'] = None
|
||||
|
||||
return item
|
||||
|
||||
async def get_stock_screener(con):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user