Dmitry Beresnev commited on
Commit Β·
92860fb
1
Parent(s): e918eaf
fix breaking news banner
Browse filesFiles changed (2)
352 unmodified lines353354355356357358359360361362352 unmodified linesdef display_breaking_news_banner(df: pd.DataFrame):"""Display breaking news banner at the top with TradingView styling and ML-based impact score."""breaking = df[df['is_breaking'] == True] if not df.empty and 'is_breaking' in df.columns else pd.DataFrame()if not breaking.empty:latest = breaking.iloc[0]# Escape HTMLsummary = html_module.escape(latest.get('summary', '').strip())352 unmodified lines353354355356357358359360361362363352 unmodified linesdef display_breaking_news_banner(df: pd.DataFrame):"""Display breaking news banner at the top with TradingView styling and ML-based impact score."""# With ML-based scoring, we trust that the passed DataFrame already contains# the highest-impact news, so no need to filter by is_breaking# (The scorer already selected the most impactful news)if not df.empty:latest = df.iloc[0]# Escape HTMLsummary = html_module.escape(latest.get('summary', '').strip())
310 unmodified lines3113123133143153161 unmodified line31831932032132232332432532632732832933033133233333433533633733833934034134236 unmodified lines379380381382383384385386133 unmodified lines520521522523524525310 unmodified lines'ai_tech': future_ai_tech}for source_name, future in futures.items():try:result_df, error = future.result(timeout=90) # 90 second timeout per source1 unmodified lineif source_name == 'twitter':twitter_df = result_dfif error:st.warning(error)elif source_name == 'reddit':reddit_df = result_dfif error:st.warning(error)elif source_name == 'rss':rss_all_df = result_dfif error:st.warning(error)elif source_name == 'ai_tech':ai_tech_df = result_dfif error:st.warning(error)# Get main page news subset for RSSif not rss_all_df.empty and 'from_web' in rss_all_df.columns:rss_main_df = rss_all_df[rss_all_df['from_web'] == True].copy()except Exception as e:st.warning(f"Error fetching {source_name} news: {e}")# Clear force refresh flag after fetching is completeif force_refresh:36 unmodified linesbreaking_df = pd.DataFrame([breaking_news_items[0]])display_breaking_news_banner(breaking_df)else:# If no high-impact news found, show informational messagest.info("π Monitoring financial markets - no high-impact breaking news at this time.")st.markdown("---")133 unmodified lines</style>""", unsafe_allow_html=True)# Auto-refresh logicif auto_refresh:import time310 unmodified lines3113123133143153163173183191 unmodified line32132232332432532632732832933033133233333433533633733833934034134234334434536 unmodified lines382383384385386387388389390391392393394395396133 unmodified lines530531532533534535536537538539540541310 unmodified lines'ai_tech': future_ai_tech}# Track errors to display later (avoid cluttering top of page)fetch_errors = []for source_name, future in futures.items():try:result_df, error = future.result(timeout=90) # 90 second timeout per source1 unmodified lineif source_name == 'twitter':twitter_df = result_dfif error:fetch_errors.append(error)elif source_name == 'reddit':reddit_df = result_dfif error:fetch_errors.append(error)elif source_name == 'rss':rss_all_df = result_dfif error:fetch_errors.append(error)# Get main page news subset for RSSif not rss_all_df.empty and 'from_web' in rss_all_df.columns:rss_main_df = rss_all_df[rss_all_df['from_web'] == True].copy()elif source_name == 'ai_tech':ai_tech_df = result_dfif error:fetch_errors.append(error)except Exception as e:fetch_errors.append(f"Error fetching {source_name} news: {e}")# Clear force refresh flag after fetching is completeif force_refresh:36 unmodified linesbreaking_df = pd.DataFrame([breaking_news_items[0]])display_breaking_news_banner(breaking_df)else:# If no high-impact news found, show informational message with scoreif breaking_news_items:top_score = breaking_news_items[0]['breaking_score']st.info(f"π Monitoring financial markets - highest impact score: {top_score:.1f}/100 (threshold: 40)")else:st.info("π Monitoring financial markets - no news items available for scoring")else:# No news data available at allst.info("π Loading financial news - breaking news banner will appear when data is available")st.markdown("---")133 unmodified lines</style>""", unsafe_allow_html=True)# Display fetch errors in expander (less intrusive)if 'fetch_errors' in locals() and fetch_errors:with st.expander("β οΈ Source Fetch Warnings", expanded=False):for error in fetch_errors:st.caption(f"β’ {error}")# Auto-refresh logicif auto_refresh:import time
app/components/news.py+5-4
app/pages/05_Dashboard.py+26-10