Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -357,29 +357,24 @@ async def scrape_webpage(url):
|
|
357 |
|
358 |
@time_logger
|
359 |
async def raw_news(raw_query, subqueries, todays_news_func_call, ticker):
|
360 |
-
|
361 |
tasks = [get_the_ticker_stat(ticker),
|
362 |
get_the_ticker_news(ticker),
|
363 |
get_google_news(subqueries),
|
364 |
-
scrape_webpage(
|
365 |
try:
|
366 |
ticker_stats, ticker_news, google_news, swot_analysis = await asyncio.gather(*tasks)
|
367 |
except Exception as exc:
|
368 |
-
logging.error(f'
|
369 |
|
370 |
if ticker_news:
|
371 |
ticker_financials, reports = ticker_news
|
372 |
-
|
373 |
-
news_google = results.get('google_news', '')
|
374 |
-
news_data = results.get('swot_analysis', '')
|
375 |
|
376 |
# logging.info("Brokers report link %s", reports)
|
|
|
377 |
for ticker_stat in ticker_stats:
|
378 |
ticker_stats_str += json.dumps(ticker_stat).replace("&", "'").replace("'", "'").replace(""", "'").replace("Link", "").replace("Heading", "").replace("Body", "").replace("Text", "").replace("{", "").replace("}", "")
|
379 |
|
380 |
-
# logging.info("All ticker stat: %s", ticker_stats_str)
|
381 |
-
# logging.info("SWOT data successfully scraped")
|
382 |
-
|
383 |
return swot_analysis, ticker_stats_str, ticker_financials, reports, google_news
|
384 |
|
385 |
def format_prompt(message, history):
|
@@ -448,7 +443,6 @@ def generate_final_response(prompt, history, context_files=[], ticker_stats=[],
|
|
448 |
elif chat_completion_params['todays_news_flag'] and len(ticker)>0:
|
449 |
for tick in chat_completion_params["stock_name"]:
|
450 |
news_googles.append(f"Latest News for {tick}\n\n {asyncio.run(get_google_news(subqueries))}")
|
451 |
-
logging.info(news_googles)
|
452 |
elif (chat_completion_params['follow_up_query'] and ticker_stats != []) or (display_ticker == ticker and ticker_stats != []):
|
453 |
# logging.info("\n\nAssigned into a followup query\n\n")
|
454 |
chat_completion_params['follow_up_query'] = True
|
|
|
357 |
|
358 |
@time_logger
|
359 |
async def raw_news(raw_query, subqueries, todays_news_func_call, ticker):
|
360 |
+
swot_analysis_link = f'https://widgets.trendlyne.com/web-widget/swot-widget/Poppins/{urllib.parse.quote(ticker)}/'
|
361 |
tasks = [get_the_ticker_stat(ticker),
|
362 |
get_the_ticker_news(ticker),
|
363 |
get_google_news(subqueries),
|
364 |
+
scrape_webpage(swot_analysis_link)]
|
365 |
try:
|
366 |
ticker_stats, ticker_news, google_news, swot_analysis = await asyncio.gather(*tasks)
|
367 |
except Exception as exc:
|
368 |
+
logging.error(f'gathering all data in parllel failed with an exception: {exc}')
|
369 |
|
370 |
if ticker_news:
|
371 |
ticker_financials, reports = ticker_news
|
|
|
|
|
|
|
372 |
|
373 |
# logging.info("Brokers report link %s", reports)
|
374 |
+
ticker_stats_str = ''
|
375 |
for ticker_stat in ticker_stats:
|
376 |
ticker_stats_str += json.dumps(ticker_stat).replace("&", "'").replace("'", "'").replace(""", "'").replace("Link", "").replace("Heading", "").replace("Body", "").replace("Text", "").replace("{", "").replace("}", "")
|
377 |
|
|
|
|
|
|
|
378 |
return swot_analysis, ticker_stats_str, ticker_financials, reports, google_news
|
379 |
|
380 |
def format_prompt(message, history):
|
|
|
443 |
elif chat_completion_params['todays_news_flag'] and len(ticker)>0:
|
444 |
for tick in chat_completion_params["stock_name"]:
|
445 |
news_googles.append(f"Latest News for {tick}\n\n {asyncio.run(get_google_news(subqueries))}")
|
|
|
446 |
elif (chat_completion_params['follow_up_query'] and ticker_stats != []) or (display_ticker == ticker and ticker_stats != []):
|
447 |
# logging.info("\n\nAssigned into a followup query\n\n")
|
448 |
chat_completion_params['follow_up_query'] = True
|