Dmitry Beresnev commited on
Commit ·
84f7cdc
1
Parent(s): 92860fb
fix AI news in dashboard
Browse filesFiles changed (2)
340 unmodified lines341342343344345346347348349350351352353354355356357358168 unmodified lines527528529530531532533534535536537538539540541542543544518519520521522523524525526527528529530531545546547548549550551552553554555556557558559560561340 unmodified lines except Exception as e: fetch_errors.append(f"Error fetching {source_name} news: {e}")
# Debug output (remove in production)if st.session_state.get('debug_mode', False): st.write("### Debug: News Fetch Results") st.write(f"- Twitter: {len(twitter_df)} items") st.write(f"- Reddit: {len(reddit_df)} items") st.write(f"- RSS: {len(rss_all_df)} items") st.write(f"- AI/Tech: {len(ai_tech_df)} items") if fetch_errors: st.write(f"- Errors: {len(fetch_errors)}") for err in fetch_errors: st.write(f" - {err}")
# Clear force refresh flag after fetching is completeif force_refresh: st.session_state.force_refresh = False168 unmodified lines height="700px" ) else: # Debug: Check if there's an AI/Tech specific error ai_tech_error = next((err for err in fetch_errors if 'ai_tech' in err.lower() or 'AI/Tech' in err), None) if 'fetch_errors' in locals() else None
if ai_tech_error: # Show error message st.markdown(f""" <div style="background: linear-gradient(135deg, #1E222D 0%, #131722 100%); border: 1px solid #2A2E39; border-radius: 8px; padding: 30px; text-align: center;"> <div style="font-size: 48px; margin-bottom: 16px;">⚠️</div> <div style="color: #D1D4DC; font-size: 16px; font-weight: 600; margin-bottom: 8px;">AI & Tech News Unavailable</div> <div style="color: #787B86; font-size: 13px;">{ai_tech_error}</div> </div> """, unsafe_allow_html=True) else: # Show loading message st.markdown(""" st.markdown(""" <div style="background: linear-gradient(135deg, #1E222D 0%, #131722 100%); border: 1px solid #2A2E39; border-radius: 8px; padding: 30px; text-align: center;"> <div style="font-size: 48px; margin-bottom: 16px; animation: pulse 2s ease-in-out infinite;">⏳</div> <div style="color: #D1D4DC; font-size: 16px; font-weight: 600; margin-bottom: 8px;">Loading AI & Tech News</div> <div style="color: #787B86; font-size: 13px;">Aggregating from tech blogs & research...</div> <div style="color: #787B86; font-size: 12px; margin-top: 8px; opacity: 0.7;">OpenAI, Google AI, Microsoft, Meta & more</div> </div> <style> @keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.6; transform: scale(1.1); } } </style> """, unsafe_allow_html=True) <div style="background: linear-gradient(135deg, #1E222D 0%, #131722 100%); border: 1px solid #2A2E39; border-radius: 8px; padding: 30px; text-align: center;"> <div style="font-size: 48px; margin-bottom: 16px; animation: pulse 2s ease-in-out infinite;">⏳</div> <div style="color: #D1D4DC; font-size: 16px; font-weight: 600; margin-bottom: 8px;">Loading AI & Tech News</div> <div style="color: #787B86; font-size: 13px;">Aggregating from tech blogs & research...</div> <div style="color: #787B86; font-size: 12px; margin-top: 8px; opacity: 0.7;">OpenAI, Google AI, Microsoft, Meta & more</div> <div style="color: #FF9500; font-size: 12px; margin-top: 12px;">If this persists, check the "Source Fetch Warnings" section below</div> </div> <style> @keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.6; transform: scale(1.1); } } </style> """, unsafe_allow_html=True)
# Display fetch errors in expander (less intrusive)if 'fetch_errors' in locals() and fetch_errors:123345626 unmodified lines3334353637383910 unmodified lines50515252535455561 unmodified line5859606061626364247 unmodified lines31231331431431531631731822 unmodified lines341342343344345346347348349350351"""Unified News Caching SystemCentralized cache manager for Twitter, Reddit, and RSS news feedsCentralized cache manager for Twitter, Reddit, RSS, and AI/Tech news feeds"""
import hashlib26 unmodified lines 'twitter': {'raw_news': [], 'last_fetch': None, 'ttl': default_ttl}, 'reddit': {'raw_news': [], 'last_fetch': None, 'ttl': default_ttl}, 'rss': {'raw_news': [], 'last_fetch': None, 'ttl': default_ttl}, 'ai_tech': {'raw_news': [], 'last_fetch': None, 'ttl': default_ttl}, 'dedup_index': {}, # Global deduplication index 'filtered_cache': {} # Cached filtered results }10 unmodified lines Get news from cache or fetch fresh if needed
Args: source: News source ('twitter', 'reddit', 'rss') source: News source ('twitter', 'reddit', 'rss', 'ai_tech') fetcher_func: Function to fetch fresh news force_refresh: If True, bypass cache and fetch fresh **kwargs: Arguments to pass to fetcher_func1 unmodified line Returns: List of news items """ if source not in ['twitter', 'reddit', 'rss']: if source not in ['twitter', 'reddit', 'rss', 'ai_tech']: logger.error(f"Invalid source: {source}") return []
247 unmodified lines self._clear_source_from_dedup(source) logger.info(f"🗑️ Cleared cache for {source}") else: for src in ['twitter', 'reddit', 'rss']: for src in ['twitter', 'reddit', 'rss', 'ai_tech']: self.cache[src] = {'raw_news': [], 'last_fetch': None, 'ttl': 180} self.cache['dedup_index'] = {} self.cache['filtered_cache'] = {}22 unmodified lines 'age_seconds': self._get_cache_age('rss'), 'is_valid': self._is_cache_valid('rss') }, 'ai_tech': { 'items': len(self.cache['ai_tech']['raw_news']), 'age_seconds': self._get_cache_age('ai_tech'), 'is_valid': self._is_cache_valid('ai_tech') }, 'dedup_index_size': len(self.cache['dedup_index']), 'filtered_cache_size': len(self.cache['filtered_cache']) }app/pages/05_Dashboard.py+41-14
app/utils/news_cache.py+10-4