Dmitry Beresnev commited on
Commit ·
84f7cdc
1
Parent(s): 92860fb
fix AI news in dashboard
Browse filesFiles changed (2)
340 unmodified lines341342343344345346168 unmodified lines515516517518519520521522523524525526527528529530531532533534340 unmodified linesexcept Exception as e:fetch_errors.append(f"Error fetching {source_name} news: {e}")# Clear force refresh flag after fetching is completeif force_refresh:st.session_state.force_refresh = False168 unmodified linesheight="700px")else: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)# Display fetch errors in expander (less intrusive)if 'fetch_errors' in locals() and fetch_errors:340 unmodified lines341342343344345346347348349350351352353354355356357358168 unmodified lines527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561340 unmodified linesexcept 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 linesheight="700px")else:# Debug: Check if there's an AI/Tech specific errorai_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 Noneif ai_tech_error:# Show error messagest.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 messagest.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="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:
12345626 unmodified lines33343536373810 unmodified lines495051525354551 unmodified line57585960616263247 unmodified lines31131231331431531631722 unmodified lines340341342343344345"""Unified News Caching SystemCentralized cache manager for Twitter, Reddit, and RSS 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},'dedup_index': {}, # Global deduplication index'filtered_cache': {} # Cached filtered results}10 unmodified linesGet news from cache or fetch fresh if neededArgs:source: News source ('twitter', 'reddit', 'rss')fetcher_func: Function to fetch fresh newsforce_refresh: If True, bypass cache and fetch fresh**kwargs: Arguments to pass to fetcher_func1 unmodified lineReturns:List of news items"""if source not in ['twitter', 'reddit', 'rss']:logger.error(f"Invalid source: {source}")return []247 unmodified linesself._clear_source_from_dedup(source)logger.info(f"🗑️ Cleared cache for {source}")else:for src in ['twitter', 'reddit', 'rss']: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')},'dedup_index_size': len(self.cache['dedup_index']),'filtered_cache_size': len(self.cache['filtered_cache'])}12345626 unmodified lines3334353637383910 unmodified lines505152535455561 unmodified line58596061626364247 unmodified lines31231331431531631731822 unmodified lines341342343344345346347348349350351"""Unified News Caching SystemCentralized 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 linesGet news from cache or fetch fresh if neededArgs:source: News source ('twitter', 'reddit', 'rss', 'ai_tech')fetcher_func: Function to fetch fresh newsforce_refresh: If True, bypass cache and fetch fresh**kwargs: Arguments to pass to fetcher_func1 unmodified lineReturns:List of news items"""if source not in ['twitter', 'reddit', 'rss', 'ai_tech']:logger.error(f"Invalid source: {source}")return []247 unmodified linesself._clear_source_from_dedup(source)logger.info(f"🗑️ Cleared cache for {source}")else: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