Dmitry Beresnev commited on
Commit ·
a8aef2e
1
Parent(s): 7ca0d9b
optimize news module performance, improve news UI, etc
Browse filesFiles changed (3)
5 unmodified lines6789101112132 unmodified lines1617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909175 unmodified lines1671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012025 unmodified linesimport html as html_moduledef display_news_card(news_item: dict):"""Display a single news card with professional styling using Streamlit components."""# Calculate time agotime_diff = datetime.now() - news_item['timestamp']2 unmodified lineselif time_diff.seconds < 3600:time_ago = f"{time_diff.seconds // 60}m ago"else:time_ago = f"{time_diff.seconds // 3600}h ago"# Create container with custom stylingwith st.container():# Add custom CSS for this cardst.markdown("""<style>.news-card {background: linear-gradient(135deg, #1f2937 0%, #111827 100%);border: 1px solid #374151;border-radius: 12px;padding: 20px;margin-bottom: 16px;}</style>""", unsafe_allow_html=True)# Header row with source and badgescol1, col2 = st.columns([3, 1])with col1:# Source and badges in one linebadge_cols = st.columns([2, 1, 1, 1])with badge_cols[0]:st.markdown(f"**:blue[{news_item['source']}]**")with badge_cols[1]:if news_item['impact'] == 'high':st.markdown("🔴 **HIGH**")elif news_item['impact'] == 'medium':st.markdown("🟡 **MED**")else:st.markdown("🟢 **LOW**")with badge_cols[2]:sentiment_emoji = {'positive': '📈', 'negative': '📉', 'neutral': '➡️'}st.markdown(f"{sentiment_emoji.get(news_item['sentiment'], '➡️')} {news_item['sentiment'].title()}")with badge_cols[3]:st.markdown(f"**#{news_item['category']}**")with col2:st.markdown(f"[**Read More →**]({news_item['url']})")# Title/Summaryst.markdown(f"### {news_item.get('summary', '').strip()}")# Meta informationst.caption(f"🕐 {time_ago}")st.markdown("---")def display_news_feed(df: pd.DataFrame, max_items: int = 20):"""Display a feed of news items."""if df.empty:st.info("📭 No news available. Adjust your filters or refresh the feed.")return# Add custom CSS for animationsst.markdown("""<style>@keyframes pulse {0%, 100% { opacity: 1; }50% { opacity: 0.6; }}</style>""", unsafe_allow_html=True)# Display news itemsfor idx, row in df.head(max_items).iterrows():display_news_card(row.to_dict())def display_news_statistics(stats: dict):75 unmodified linesdef display_breaking_news_banner(df: pd.DataFrame):"""Display breaking news banner at the top using Streamlit components."""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]# Create container with red background stylingwith st.container():st.markdown("""<style>.breaking-news-container {background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);border-radius: 12px;padding: 20px;margin-bottom: 24px;border: 2px solid #fca5a5;}</style>""", unsafe_allow_html=True)# Layout with emoji and contentcol1, col2, col3 = st.columns([1, 8, 2])with col1:st.markdown("# 🚨")with col2:st.markdown(f"**:red[BREAKING NEWS • {latest['source'].upper()}]**")st.markdown(f"## {latest.get('summary', '').strip()}")with col3:st.markdown(f"[**READ NOW →**]({latest['url']})")5 unmodified lines6789101112132 unmodified lines16171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625775 unmodified lines3333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734745 unmodified linesimport html as html_moduledef display_tradingview_news_card(news_item: dict):"""Display a single news card with TradingView-inspired styling."""# Calculate time agotime_diff = datetime.now() - news_item['timestamp']2 unmodified lineselif time_diff.seconds < 3600:time_ago = f"{time_diff.seconds // 60}m ago"else:hours = time_diff.seconds // 3600time_ago = f"{hours}h ago" if hours < 24 else f"{time_diff.days}d ago"# Impact badge colors (TradingView style)impact_colors = {'high': '#F23645', # Red'medium': '#FF9800', # Orange'low': '#089981' # Green}# Sentiment colorssentiment_colors = {'positive': '#089981', # Green'negative': '#F23645', # Red'neutral': '#787B86' # Gray}impact_color = impact_colors.get(news_item['impact'], '#787B86')sentiment_color = sentiment_colors.get(news_item['sentiment'], '#787B86')# Escape HTML in textsummary = html_module.escape(news_item.get('summary', '').strip())source = html_module.escape(news_item['source'])category = html_module.escape(news_item['category'])url = html_module.escape(news_item['url'])# TradingView-style card HTMLcard_html = f"""<div style="background: linear-gradient(135deg, #1E222D 0%, #131722 100%);border: 1px solid #2A2E39;border-radius: 8px;padding: 16px;margin-bottom: 12px;transition: all 0.2s ease;cursor: pointer;position: relative;overflow: hidden;" onmouseover="this.style.borderColor='#3861FB'; this.style.transform='translateY(-2px)'; this.style.boxShadow='0 4px 12px rgba(56, 97, 251, 0.15)';"onmouseout="this.style.borderColor='#2A2E39'; this.style.transform='translateY(0)'; this.style.boxShadow='none';"><!-- Left colored indicator bar --><div style="position: absolute;left: 0;top: 0;bottom: 0;width: 3px;background: {impact_color};"></div><!-- Header row --><div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; margin-left: 8px;"><div style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap;"><span style="color: #3861FB;font-weight: 600;font-size: 13px;font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;">{source}</span><span style="background: {impact_color};color: white;padding: 2px 8px;border-radius: 4px;font-size: 10px;font-weight: 700;letter-spacing: 0.5px;">{news_item['impact'].upper()}</span><span style="color: {sentiment_color};font-size: 11px;font-weight: 600;padding: 2px 6px;border: 1px solid {sentiment_color};border-radius: 4px;">{'▲' if news_item['sentiment'] == 'positive' else '▼' if news_item['sentiment'] == 'negative' else '●'} {news_item['sentiment'].upper()}</span><span style="color: #787B86;font-size: 11px;background: rgba(120, 123, 134, 0.1);padding: 2px 6px;border-radius: 4px;">#{category}</span></div><span style="color: #787B86; font-size: 11px; white-space: nowrap;">{time_ago}</span></div><!-- News summary --><div style="color: #D1D4DC;font-size: 14px;line-height: 1.5;margin-bottom: 8px;margin-left: 8px;font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;">{summary}</div><!-- Read more link --><a href="{url}" target="_blank" style="color: #3861FB;font-size: 12px;text-decoration: none;margin-left: 8px;display: inline-flex;align-items: center;gap: 4px;font-weight: 500;" onmouseover="this.style.color='#5880FF';" onmouseout="this.style.color='#3861FB';">Read Full Story →</a></div>"""st.markdown(card_html, unsafe_allow_html=True)def display_news_card(news_item: dict):"""Wrapper to maintain compatibility - calls TradingView-style card."""display_tradingview_news_card(news_item)def display_scrollable_news_section(df: pd.DataFrame, section_title: str, section_icon: str,section_subtitle: str, max_items: int = 20, height: str = "600px"):"""Display a scrollable news section with TradingView styling."""if df.empty:st.markdown(f"""<div style="background: linear-gradient(135deg, #1E222D 0%, #131722 100%);border: 1px solid #2A2E39;border-radius: 8px;padding: 20px;text-align: center;color: #787B86;"><p style="font-size: 16px; margin: 0;">📭 No news available for this section</p></div>""", unsafe_allow_html=True)return# Section headerst.markdown(f"""<div style="background: linear-gradient(135deg, #2A2E39 0%, #1E222D 100%);border: 1px solid #363A45;border-radius: 8px 8px 0 0;padding: 16px 20px;margin-bottom: 0;"><div style="display: flex; justify-content: space-between; align-items: center;"><div><h3 style="color: #D1D4DC;margin: 0;font-size: 18px;font-weight: 600;font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;">{section_icon} {section_title}</h3><p style="color: #787B86;margin: 4px 0 0 0;font-size: 12px;">{section_subtitle}</p></div><div style="background: rgba(56, 97, 251, 0.15);color: #3861FB;padding: 6px 12px;border-radius: 6px;font-size: 13px;font-weight: 600;">{len(df.head(max_items))} stories</div></div></div>""", unsafe_allow_html=True)# Scrollable container with TradingView-style scrollbarst.markdown(f"""<style>.news-scroll-container {{height: {height};overflow-y: auto;background: #0D0E13;border: 1px solid #2A2E39;border-top: none;border-radius: 0 0 8px 8px;padding: 16px;}}/* TradingView-style scrollbar */.news-scroll-container::-webkit-scrollbar {{width: 8px;}}.news-scroll-container::-webkit-scrollbar-track {{background: #1E222D;border-radius: 4px;}}.news-scroll-container::-webkit-scrollbar-thumb {{background: #363A45;border-radius: 4px;}}.news-scroll-container::-webkit-scrollbar-thumb:hover {{background: #434651;}}</style>""", unsafe_allow_html=True)# Start scrollable containerst.markdown('<div class="news-scroll-container">', unsafe_allow_html=True)# Display news itemsfor idx, row in df.head(max_items).iterrows():display_tradingview_news_card(row.to_dict())# End scrollable containerst.markdown('</div>', unsafe_allow_html=True)def display_news_feed(df: pd.DataFrame, max_items: int = 20):"""Display a feed of news items (legacy compatibility)."""if df.empty:st.info("📭 No news available. Adjust your filters or refresh the feed.")return# Display news itemsfor idx, row in df.head(max_items).iterrows():display_tradingview_news_card(row.to_dict())def display_news_statistics(stats: dict):75 unmodified linesdef display_breaking_news_banner(df: pd.DataFrame):"""Display breaking news banner at the top with TradingView styling."""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())source = html_module.escape(latest['source'])url = html_module.escape(latest['url'])# Calculate time agotime_diff = datetime.now() - latest['timestamp']if time_diff.seconds < 60:time_ago = f"{time_diff.seconds}s ago"elif time_diff.seconds < 3600:time_ago = f"{time_diff.seconds // 60}m ago"else:hours = time_diff.seconds // 3600time_ago = f"{hours}h ago" if hours < 24 else f"{time_diff.days}d ago"# TradingView-style breaking news bannerbanner_html = f"""<style>@keyframes pulse-glow {{0%, 100% {{ box-shadow: 0 0 20px rgba(242, 54, 69, 0.6); }}50% {{ box-shadow: 0 0 30px rgba(242, 54, 69, 0.9); }}}}@keyframes slide-in {{from {{ transform: translateX(-10px); opacity: 0; }}to {{ transform: translateX(0); opacity: 1; }}}}</style><div style="background: linear-gradient(135deg, #F23645 0%, #C91B28 100%);border: 2px solid #FF6B78;border-radius: 12px;padding: 20px 24px;margin-bottom: 24px;animation: pulse-glow 2s ease-in-out infinite;position: relative;overflow: hidden;"><!-- Animated background pattern --><div style="position: absolute;top: 0;left: 0;right: 0;bottom: 0;background: repeating-linear-gradient(45deg,transparent,transparent 10px,rgba(255, 255, 255, 0.03) 10px,rgba(255, 255, 255, 0.03) 20px);pointer-events: none;"></div><!-- Content --><div style="position: relative; z-index: 1;"><div style="display: flex; align-items: center; gap: 16px; margin-bottom: 12px;"><!-- Animated icon --><div style="font-size: 32px;animation: pulse-glow 1s ease-in-out infinite;filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));">🚨</div><!-- Header --><div style="flex: 1;"><div style="color: white;font-size: 14px;font-weight: 700;letter-spacing: 1.5px;text-transform: uppercase;margin-bottom: 4px;font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);">⚡ Breaking News</div><div style="color: rgba(255, 255, 255, 0.9);font-size: 11px;display: flex;align-items: center;gap: 8px;"><span style="background: rgba(255, 255, 255, 0.2);padding: 2px 8px;border-radius: 4px;font-weight: 600;">{source}</span><span style="opacity: 0.8;">•</span><span style="opacity: 0.8;">{time_ago}</span></div></div><!-- Read button --><a href="{url}" target="_blank" style="background: white;color: #F23645;padding: 10px 20px;border-radius: 6px;font-size: 13px;font-weight: 700;text-decoration: none;display: inline-flex;align-items: center;gap: 6px;transition: all 0.2s ease;box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);" onmouseover="this.style.transform='translateY(-2px)'; this.style.boxShadow='0 4px 12px rgba(0, 0, 0, 0.3)';"onmouseout="this.style.transform='translateY(0)'; this.style.boxShadow='0 2px 8px rgba(0, 0, 0, 0.2)';">READ NOW →</a></div><!-- News summary --><div style="color: white;font-size: 16px;font-weight: 500;line-height: 1.5;margin-left: 48px;font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);animation: slide-in 0.5s ease-out;">{summary}</div></div></div>"""st.markdown(banner_html, unsafe_allow_html=True)
11 unmodified lines12131415161718192021198 unmodified lines22022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826911 unmodified linesfrom components.styles import DARK_THEME_CSSfrom components.news import (display_news_feed,display_news_statistics,display_category_breakdown,display_breaking_news_banner)# Import news scrapers198 unmodified linesst.markdown("---")# ---- SECTION 1: Twitter/X Breaking News (Highest Priority) ----st.markdown("## 🐦 Twitter/X Financial News Feed")st.caption("Real-time breaking news from premium Twitter/X accounts (WalterBloomberg, Reuters, Bloomberg, FT, etc.)")if not twitter_filtered.empty:display_news_feed(twitter_filtered, max_items=15)elif not twitter_df.empty:st.info("📭 No Twitter news matches your current filters.")else:st.info("⏳ Twitter news scraping in progress... This may take 30-60 seconds on first load.")st.markdown("---")# ---- SECTION 2: Main Page News (Web-Scraped) ----st.markdown("## 🔥 Top Stories from Main Pages")st.caption("Latest headlines directly scraped from news source homepages")if not rss_main_filtered.empty:display_news_feed(rss_main_filtered, max_items=10)elif not rss_main_df.empty:st.info("📭 No main page news matches your filters.")else:st.info("⏳ Main page news will appear here...")st.markdown("---")# ---- SECTION 3: RSS Feed News (Lowest Priority) ----col1, col2, col3 = st.columns([2, 1, 1])with col1:st.markdown("## 📰 RSS Feed News")with col2:show_count = st.selectbox("Show", [10, 20, 50, 100], index=1, label_visibility="collapsed")with col3:if not rss_all_filtered.empty:st.caption(f"Displaying {min(show_count, len(rss_all_filtered))} of {len(rss_all_filtered)} stories")st.caption("Aggregated news from RSS feeds across all sources")if not rss_all_filtered.empty:display_news_feed(rss_all_filtered, max_items=show_count)elif not rss_all_df.empty:st.info("📭 No RSS news matches your current filters.")else:st.info("⏳ RSS feed news will appear here...")# Auto-refresh logicif auto_refresh:11 unmodified lines12131415161718192021198 unmodified lines22022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527611 unmodified linesfrom components.styles import DARK_THEME_CSSfrom components.news import (display_news_statistics,display_category_breakdown,display_breaking_news_banner,display_scrollable_news_section)# Import news scrapers198 unmodified linesst.markdown("---")# ---- THREE-COLUMN SCROLLABLE NEWS LAYOUT (TradingView Style) ----col1, col2, col3 = st.columns(3)with col1:# SECTION 1: Twitter/X Breaking Newsif not twitter_filtered.empty:display_scrollable_news_section(twitter_filtered,section_title="Twitter/X News",section_icon="🐦",section_subtitle="Real-time breaking news from premium accounts",max_items=50,height="700px")elif not twitter_df.empty:st.info("📭 No Twitter news matches your current filters.")else:st.info("⏳ Twitter news scraping in progress... This may take 30-60 seconds on first load.")with col2:# SECTION 2: Main Page News (Web-Scraped)if not rss_main_filtered.empty:display_scrollable_news_section(rss_main_filtered,section_title="Top Headlines",section_icon="🔥",section_subtitle="Latest from main pages",max_items=50,height="700px")elif not rss_main_df.empty:st.info("📭 No main page news matches your filters.")else:st.info("⏳ Main page news will appear here...")with col3:# SECTION 3: RSS Feed Newsif not rss_all_filtered.empty:display_scrollable_news_section(rss_all_filtered,section_title="RSS Feed",section_icon="📰",section_subtitle="Aggregated from all sources",max_items=100,height="700px")elif not rss_all_df.empty:st.info("📭 No RSS news matches your current filters.")else:st.info("⏳ RSS feed news will appear here...")# Auto-refresh logicif auto_refresh:
207 unmodified lines20820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725849 unmodified lines3083093103113123133142 unmodified lines3173183193203213223233243253263273283293303313323338 unmodified lines342343344345346347348207 unmodified lineslogger.warning("Chromium not found in standard paths")return '/usr/bin/chromium' # Fallbackdef _scrape_twitter_profile(self, source_name: str, source_info: Dict, timeout: int = 15) -> List[Dict]:"""Scrape tweets from a single Twitter profile using Playwright"""if not PLAYWRIGHT_AVAILABLE:logger.warning("Playwright not available")return []try:with sync_playwright() as p:# Launch lightweight browserbrowser = p.chromium.launch(executable_path=self.chromium_path,headless=True,args=['--disable-blink-features=AutomationControlled'])context = browser.new_context(user_agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')page = context.new_page()# Block images, fonts, and css for speeddef route_intercept(route):if route.request.resource_type in ["image", "media", "font", "stylesheet"]:route.abort()else:route.continue_()page.route("**/*", route_intercept)# Navigate to profilelogger.info(f"Scraping {source_name} from {source_info['url']}")page.goto(source_info['url'], timeout=timeout * 1000)# Wait for tweets to loadtry:page.wait_for_selector("article", timeout=timeout * 1000)except PlaywrightTimeoutError:logger.warning(f"Timeout waiting for tweets from {source_name}")browser.close()return []# Extract tweet textstweet_elements = page.locator("article div[data-testid='tweetText']").all()news_items = []for idx, element in enumerate(tweet_elements[:20]): # Limit to 20 most recenttry:text = element.text_content()if not text or len(text) < 10:49 unmodified linesdef scrape_twitter_news(_self, max_tweets: int = 100) -> List[Dict]:"""Scrape latest financial news from Twitter using PlaywrightRuns in parallel for better performance"""if not PLAYWRIGHT_AVAILABLE:logger.info("Playwright not available - using mock data")2 unmodified linesall_news = []seen_texts = set()# Scrape sources in parallel with timeoutwith ThreadPoolExecutor(max_workers=3) as executor:futures = []for name, info in _self.SOURCES.items():future = executor.submit(_self._scrape_twitter_profile, name, info, timeout=15)futures.append((future, name))for future, source_name in futures:try:# Wait max 20 seconds per sourcenews_items = future.result(timeout=20)# Deduplicate based on text similarityunique_items = []8 unmodified lineslogger.info(f"Fetched {len(unique_items)} unique tweets from {source_name}")except FuturesTimeoutError:logger.warning(f"Timeout scraping {source_name}")except Exception as e:logger.error(f"Error processing {source_name}: {e}")207 unmodified lines20820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426549 unmodified lines3153163173183193203212 unmodified lines3243253263273283293303313323333343353363373383393403413423433443453463473483498 unmodified lines358359360361362363364207 unmodified lineslogger.warning("Chromium not found in standard paths")return '/usr/bin/chromium' # Fallbackdef _scrape_twitter_profile(self, source_name: str, source_info: Dict, timeout: int = 12) -> List[Dict]:"""Scrape tweets from a single Twitter profile using Playwright (optimized for speed)"""if not PLAYWRIGHT_AVAILABLE:logger.warning("Playwright not available")return []try:with sync_playwright() as p:# Launch lightweight browser with aggressive performance flagsbrowser = p.chromium.launch(executable_path=self.chromium_path,headless=True,args=['--disable-blink-features=AutomationControlled','--disable-dev-shm-usage', # Overcome limited resource problems'--no-sandbox', # Required for some environments'--disable-setuid-sandbox','--disable-gpu', # Not needed in headless'--disable-software-rasterizer'])context = browser.new_context(user_agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')page = context.new_page()# Block images, fonts, css, and videos for maximum speeddef route_intercept(route):if route.request.resource_type in ["image", "media", "font", "stylesheet", "video"]:route.abort()else:route.continue_()page.route("**/*", route_intercept)# Navigate to profile with reduced timeoutlogger.info(f"Scraping {source_name}...")page.goto(source_info['url'], timeout=timeout * 1000, wait_until="domcontentloaded") # Don't wait for full load# Wait for tweets to load with reduced timeouttry:page.wait_for_selector("article", timeout=8000) # Fixed 8 second waitexcept PlaywrightTimeoutError:logger.warning(f"Timeout waiting for tweets from {source_name}")browser.close()return []# Extract tweet texts (limit to 15 for speed)tweet_elements = page.locator("article div[data-testid='tweetText']").all()news_items = []for idx, element in enumerate(tweet_elements[:15]): # Reduced from 20 to 15 for speedtry:text = element.text_content()if not text or len(text) < 10:49 unmodified linesdef scrape_twitter_news(_self, max_tweets: int = 100) -> List[Dict]:"""Scrape latest financial news from Twitter using PlaywrightRuns in parallel for better performance - 19 sources in ~30-45 seconds"""if not PLAYWRIGHT_AVAILABLE:logger.info("Playwright not available - using mock data")2 unmodified linesall_news = []seen_texts = set()# Sort sources by weight (priority) - scrape high-value sources firstsorted_sources = sorted(_self.SOURCES.items(),key=lambda x: x[1]['weight'],reverse=True)# Scrape sources in parallel with higher concurrency# 8 workers = 19 sources in 3 batches (~30-45 seconds total)with ThreadPoolExecutor(max_workers=8) as executor:futures = []for name, info in sorted_sources:# Reduced timeout for faster failuresfuture = executor.submit(_self._scrape_twitter_profile, name, info, timeout=12)futures.append((future, name))for future, source_name in futures:try:# Wait max 15 seconds per source (down from 20)news_items = future.result(timeout=15)# Deduplicate based on text similarityunique_items = []8 unmodified lineslogger.info(f"Fetched {len(unique_items)} unique tweets from {source_name}")except FuturesTimeoutError:logger.warning(f"Timeout scraping {source_name} - skipping")except Exception as e:logger.error(f"Error processing {source_name}: {e}")
app/components/news.py+353-81
app/pages/05_Dashboard.py+47-40
app/services/twitter_news_playwright.py+37-21