Dmitry Beresnev commited on
Commit Β·
e9c5fb7
1
Parent(s): ce7610c
fix news feed
Browse files6 unmodified lines789101112131 unmodified line15161718192021222324252627282930313233343536373839404142436 unmodified linesdef display_news_card(news_item: dict):"""Display a compact news card with professional styling using Streamlit components."""# Calculate time agotime_diff = datetime.now() - news_item['timestamp']1 unmodified linetime_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"# Create compact containerwith st.container():# Compact header row with all info in one linecol1, col2 = st.columns([4, 1])with col1:# Source, impact, sentiment, and category in compact formatimpact_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}")with col2:st.markdown(f"[Read β]({news_item['url']})")# Compact title/summaryst.markdown(f"**{news_item.get('summary', '').strip()}**")st.markdown("---")6 unmodified lines789101112131 unmodified line15161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676 unmodified linesdef 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']1 unmodified linetime_ago = f"{time_diff.seconds}s ago"elif 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("---")
app/components/news.py+40-16