Skip to content

Commit

Permalink
bugfixing: add only symbols that exist in db
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Jul 21, 2024
1 parent 3573993 commit 316e2c1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/cron_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 316e2c1

Please sign in to comment.