Skip to content

Commit

Permalink
update bulls bear say
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Dec 6, 2024
1 parent eddfc85 commit a50ae8e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions app/cron_bull_bear_say.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@
async def get_endpoint(session, symbol):
url = "https://api.benzinga.com/api/v1/bulls_bears_say"
querystring = {"token": api_key, "symbols": symbol}

formatted_data = {}
try:
async with session.get(url, params=querystring) as response:
res = ujson.loads(await response.text())
try:
for item in res['bulls_say_bears_say']:
date = datetime.fromtimestamp(item['updated'])
date = date.strftime("%B %d, %Y")
date = date.strftime("%Y-%m-%d %H:%M:%S")
bull_case = item['bull_case']
bear_case = item['bear_case']
formatted_data = {'date': date, 'bullSays': bull_case, 'bearSays': bear_case}
except Exception as e:
formatted_data = {}
except Exception as e:
formatted_data = {}
print(e)
with open(f"json/bull_bear_say/{symbol}.json", 'w') as file:
ujson.dump(formatted_data, file)
except:
pass
except:
pass

if formatted_data:
with open(f"json/bull_bear_say/{symbol}.json", 'w') as file:
ujson.dump(formatted_data, file)

async def run():
con = sqlite3.connect('stocks.db')

cursor = con.cursor()
cursor.execute("PRAGMA journal_mode = wal")
cursor.execute("SELECT DISTINCT symbol FROM stocks")
cursor.execute("SELECT DISTINCT symbol FROM stocks WHERE symbol NOT LIKE '%.%'")
stocks_symbols = [row[0] for row in cursor.fetchall()]
#stocks_symbols = ['NVDA']
con.close()
Expand Down

0 comments on commit a50ae8e

Please sign in to comment.