Dmitry Beresnev commited on
Commit Β·
e9c5fb7
1
Parent(s): ce7610c
fix news feed
Browse files6 unmodified lines78910101112131 unmodified line15161718191821192023212225262324252627282930313233343536373839293031323334404142434445464748495051525354555657375859606162394063646566676 unmodified lines
def display_news_card(news_item: dict): """Display a compact news card with professional styling using Streamlit components.""" """Display a single news card with professional styling using Streamlit components."""
# Calculate time ago time_diff = datetime.now() - news_item['timestamp']1 unmodified line time_ago = f"{time_diff.seconds}s ago" elif time_diff.seconds < 3600: time_ago = f"{time_diff.seconds // 60}m ago" elif time_diff.days == 0: time_ago = f"{time_diff.seconds // 3600}h ago" else: time_ago = f"{time_diff.days}d ago" time_ago = f"{time_diff.seconds // 3600}h ago"
# Create compact container # Create container with custom styling with st.container(): # Compact header row with all info in one line col1, col2 = st.columns([4, 1]) # Add custom CSS for this card st.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 badges col1, col2 = st.columns([3, 1])
with col1: # Source, impact, sentiment, and category in compact format impact_badge = "π΄" if news_item['impact'] == 'high' else "π‘" if news_item['impact'] == 'medium' else "π’" sentiment_emoji = {'positive': 'π', 'negative': 'π', 'neutral': 'β‘οΈ'} sentiment_icon = sentiment_emoji.get(news_item['sentiment'], 'β‘οΈ')
st.caption(f"**{news_item['source']}** β’ {impact_badge} {news_item['impact'].upper()} β’ {sentiment_icon} {news_item['sentiment'].title()} β’ #{news_item['category']} β’ {time_ago}") # Source and badges in one line badge_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 β]({news_item['url']})") st.markdown(f"[**Read More β**]({news_item['url']})")
# Title/Summary st.markdown(f"### {news_item.get('summary', '').strip()}")
# Compact title/summary st.markdown(f"**{news_item.get('summary', '').strip()}**") # Meta information st.caption(f"π {time_ago}")
st.markdown("---")
app/components/news.py+40-16