bugfixing

This commit is contained in:
MuslemRahimi 2024-10-07 18:15:32 +02:00
parent 1127900d04
commit 0aa2367ee4

View File

@ -49,8 +49,9 @@ async def get_analyst_insight(session, ticker):
# Summarize insights using OpenAI
async def get_summary(data):
try:
data_string = f"Insights: {data['insight']}"
response = await client.chat.completions.create(
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "Summarize analyst insights clearly and concisely in under 400 characters. Ensure the summary is professional and easy to understand. Conclude with whether the report is bullish or bearish."},
@ -62,6 +63,8 @@ async def get_summary(data):
summary = response.choices[0].message.content
data['insight'] = summary
return data
except Exception as e:
print(e)
# Process individual symbol
async def process_symbol(session, symbol):
@ -74,8 +77,10 @@ async def process_symbol(session, symbol):
old_report_id = ujson.loads(await file.read()).get('id', '')
except:
old_report_id = ''
if new_report_id != old_report_id and data['insight']:
res = await get_summary(data)
if res:
await save_json(symbol, res)
else:
print(f'Skipped: {symbol}')
@ -93,7 +98,7 @@ async def main():
con = sqlite3.connect('stocks.db')
cursor = con.cursor()
cursor.execute("SELECT DISTINCT symbol FROM stocks WHERE symbol NOT LIKE '%.%'")
stock_symbols = [row[0] for row in cursor.fetchall()]
stock_symbols = ['CXT'] #[row[0] for row in cursor.fetchall()]
con.close()
async with aiohttp.ClientSession(headers=headers) as session: