Dmitry Beresnev commited on
Commit Β·
a0ea8f4
1
Parent(s): 534d90b
fix news dashboard
Browse files296 unmodified lines297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356296 unmodified lines# Progressive loading: Display results as they arrive# Create a status placeholder to show progressstatus_placeholder = st.empty()status_placeholder.info("π Starting news fetch from 4 sources...")# Execute all news fetching operations in parallel using ThreadPoolExecutorwith ThreadPoolExecutor(max_workers=4) as executor:# Submit all tasks with source name attachedfutures_map = {executor.submit(fetch_twitter_news): 'twitter',executor.submit(fetch_reddit_news): 'reddit',executor.submit(fetch_rss_news): 'rss',executor.submit(fetch_ai_tech_news): 'ai_tech'}# Track errors and completionfetch_errors = []completed_sources = []# Process results as they complete (progressive loading)for future in as_completed(futures_map, timeout=90):source_name = futures_map[future]try:result_df, error = future.result()# Update statuscompleted_sources.append(source_name)status_placeholder.info(f"π Loaded {len(completed_sources)}/4 sources ({', '.join(completed_sources)})")if 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}")completed_sources.append(f"{source_name} (error)")status_placeholder.warning(f"β οΈ {source_name} failed, continuing with other sources...")# Clear the status message after all sources completestatus_placeholder.success(f"β Loaded {len(completed_sources)}/4 sources successfully")# Debug output (remove in production)if st.session_state.get('debug_mode', False):296 unmodified lines297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369296 unmodified lines# Progressive loading: Display results as they arrive# Create a status placeholder to show progressstatus_placeholder = st.empty()# Execute all news fetching operations in parallel using ThreadPoolExecutorwith st.spinner("π Loading news from 4 sources..."):with ThreadPoolExecutor(max_workers=4) as executor:# Submit all tasks with source name attachedfutures_map = {executor.submit(fetch_twitter_news): 'twitter',executor.submit(fetch_reddit_news): 'reddit',executor.submit(fetch_rss_news): 'rss',executor.submit(fetch_ai_tech_news): 'ai_tech'}# Track errors and completionfetch_errors = []completed_sources = []# Process results as they complete (progressive loading)try:for future in as_completed(futures_map, timeout=90):source_name = futures_map[future]try:result_df, error = future.result()# Update statuscompleted_sources.append(source_name)status_placeholder.info(f"π Loaded {len(completed_sources)}/4 sources ({', '.join(completed_sources)})")if 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}")completed_sources.append(f"{source_name} (error)")status_placeholder.warning(f"β οΈ {source_name} failed, continuing with other sources...")except TimeoutError:# Handle timeout gracefully - continue with whatever results we havefetch_errors.append("β±οΈ Some sources timed out after 90 seconds - displaying available results")status_placeholder.warning(f"β οΈ {len(completed_sources)}/4 sources loaded (some timed out)")# Mark incomplete sourcesall_sources = set(futures_map.values())incomplete_sources = all_sources - set(completed_sources)for source in incomplete_sources:fetch_errors.append(f"{source} timed out - skipped")completed_sources.append(f"{source} (timeout)")# Clear the status message after all sources completestatus_placeholder.success(f"β Loaded {len(completed_sources)}/4 sources successfully")# Debug output (remove in production)if st.session_state.get('debug_mode', False):
app/pages/05_Dashboard.py+63-50