From 316e2c15c0af684af588b7f55b575b2a7ee7c966 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sun, 21 Jul 2024 11:38:30 +0200 Subject: [PATCH] bugfixing: add only symbols that exist in db --- app/cron_dashboard.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/cron_dashboard.py b/app/cron_dashboard.py index a35af4e..31da9ee 100644 --- a/app/cron_dashboard.py +++ b/app/cron_dashboard.py @@ -9,10 +9,28 @@ import os from dotenv import load_dotenv from datetime import datetime, timedelta +import sqlite3 headers = {"accept": "application/json"} +con = sqlite3.connect('stocks.db') +etf_con = sqlite3.connect('etf.db') + +cursor = con.cursor() +cursor.execute("PRAGMA journal_mode = wal") +cursor.execute("SELECT DISTINCT symbol FROM stocks") +stock_symbols = [row[0] for row in cursor.fetchall()] + +etf_cursor = etf_con.cursor() +etf_cursor.execute("PRAGMA journal_mode = wal") +etf_cursor.execute("SELECT DISTINCT symbol FROM etfs") +etf_symbols = [row[0] for row in etf_cursor.fetchall()] + +total_symbols = stock_symbols+etf_symbols + +con.close() +etf_con.close() load_dotenv() benzinga_api_key = os.getenv('BENZINGA_API_KEY') @@ -51,11 +69,14 @@ async def run(): try: with open(f"json/options-flow/feed/data.json", 'r') as file: options_flow = ujson.load(file) + + # Filter the options_flow to include only items with ticker in total_symbol + options_flow = [item for item in options_flow if item['ticker'] in total_symbols] + options_flow = sorted(options_flow, key=lambda x: x['cost_basis'], reverse=True) options_flow = [{key: item[key] for key in ['cost_basis', 'ticker','assetType', 'date_expiration', 'put_call', 'sentiment', 'strike_price']} for item in options_flow[0:4]] except: options_flow = [] - try: with open(f"json/wiim/rss-feed/data.json", 'r') as file: wiim_feed = ujson.load(file)[0:5]