Dmitry Beresnev
commited on
Commit
Β·
ce7610c
1
Parent(s):
903cdee
fix news feed
Browse files- 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
|
| 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 |
-
|
| 19 |
time_ago = f"{time_diff.seconds // 3600}h ago"
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
# Create container
|
| 22 |
with st.container():
|
| 23 |
-
#
|
| 24 |
-
st.
|
| 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
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 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 |
-
|
| 58 |
-
st.markdown(f"[**Read More β**]({news_item['url']})")
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
-
#
|
| 64 |
-
st.
|
| 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 |
|