Dmitry Beresnev commited on
Commit
ce7610c
Β·
1 Parent(s): 903cdee

fix news feed

Browse files
Files changed (1) hide show
  1. app/components/news.py +16 -40
app/components/news.py CHANGED
@@ -7,7 +7,7 @@ import html as html_module
7
 
8
 
9
  def display_news_card(news_item: dict):
10
- """Display a single news card with professional styling using Streamlit components."""
11
 
12
  # Calculate time ago
13
  time_diff = datetime.now() - news_item['timestamp']
@@ -15,53 +15,29 @@ def display_news_card(news_item: dict):
15
  time_ago = f"{time_diff.seconds}s ago"
16
  elif time_diff.seconds < 3600:
17
  time_ago = f"{time_diff.seconds // 60}m ago"
18
- else:
19
  time_ago = f"{time_diff.seconds // 3600}h ago"
 
 
20
 
21
- # Create container with custom styling
22
  with st.container():
23
- # Add custom CSS for this card
24
- st.markdown("""
25
- <style>
26
- .news-card {
27
- background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
28
- border: 1px solid #374151;
29
- border-radius: 12px;
30
- padding: 20px;
31
- margin-bottom: 16px;
32
- }
33
- </style>
34
- """, unsafe_allow_html=True)
35
-
36
- # Header row with source and badges
37
- col1, col2 = st.columns([3, 1])
38
 
39
  with col1:
40
- # Source and badges in one line
41
- badge_cols = st.columns([2, 1, 1, 1])
42
- with badge_cols[0]:
43
- st.markdown(f"**:blue[{news_item['source']}]**")
44
- with badge_cols[1]:
45
- if news_item['impact'] == 'high':
46
- st.markdown("πŸ”΄ **HIGH**")
47
- elif news_item['impact'] == 'medium':
48
- st.markdown("🟑 **MED**")
49
- else:
50
- st.markdown("🟒 **LOW**")
51
- with badge_cols[2]:
52
- sentiment_emoji = {'positive': 'πŸ“ˆ', 'negative': 'πŸ“‰', 'neutral': '➑️'}
53
- st.markdown(f"{sentiment_emoji.get(news_item['sentiment'], '➑️')} {news_item['sentiment'].title()}")
54
- with badge_cols[3]:
55
- st.markdown(f"**#{news_item['category']}**")
56
 
57
- with col2:
58
- st.markdown(f"[**Read More β†’**]({news_item['url']})")
59
 
60
- # Title/Summary
61
- st.markdown(f"### {news_item.get('summary', '').strip()}")
62
 
63
- # Meta information
64
- st.caption(f"πŸ• {time_ago} | ❀️ {news_item['likes']:,} | πŸ”„ {news_item['retweets']:,}")
65
 
66
  st.markdown("---")
67
 
 
7
 
8
 
9
  def display_news_card(news_item: dict):
10
+ """Display a compact news card with professional styling using Streamlit components."""
11
 
12
  # Calculate time ago
13
  time_diff = datetime.now() - news_item['timestamp']
 
15
  time_ago = f"{time_diff.seconds}s ago"
16
  elif time_diff.seconds < 3600:
17
  time_ago = f"{time_diff.seconds // 60}m ago"
18
+ elif time_diff.days == 0:
19
  time_ago = f"{time_diff.seconds // 3600}h ago"
20
+ else:
21
+ time_ago = f"{time_diff.days}d ago"
22
 
23
+ # Create compact container
24
  with st.container():
25
+ # Compact header row with all info in one line
26
+ col1, col2 = st.columns([4, 1])
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  with col1:
29
+ # Source, impact, sentiment, and category in compact format
30
+ impact_badge = "πŸ”΄" if news_item['impact'] == 'high' else "🟑" if news_item['impact'] == 'medium' else "🟒"
31
+ sentiment_emoji = {'positive': 'πŸ“ˆ', 'negative': 'πŸ“‰', 'neutral': '➑️'}
32
+ sentiment_icon = sentiment_emoji.get(news_item['sentiment'], '➑️')
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ st.caption(f"**{news_item['source']}** β€’ {impact_badge} {news_item['impact'].upper()} β€’ {sentiment_icon} {news_item['sentiment'].title()} β€’ #{news_item['category']} β€’ {time_ago}")
 
35
 
36
+ with col2:
37
+ st.markdown(f"[Read β†’]({news_item['url']})")
38
 
39
+ # Compact title/summary
40
+ st.markdown(f"**{news_item.get('summary', '').strip()}**")
41
 
42
  st.markdown("---")
43