Dmitry Beresnev
commited on
Commit
Β·
e9c5fb7
1
Parent(s):
ce7610c
fix news feed
Browse files- app/components/news.py +40 -16
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,29 +15,53 @@ 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 |
-
elif time_diff.days == 0:
|
| 19 |
-
time_ago = f"{time_diff.seconds // 3600}h ago"
|
| 20 |
else:
|
| 21 |
-
time_ago = f"{time_diff.
|
| 22 |
|
| 23 |
-
# Create
|
| 24 |
with st.container():
|
| 25 |
-
#
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
with col1:
|
| 29 |
-
# Source
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
with col2:
|
| 37 |
-
st.markdown(f"[Read
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
st.
|
| 41 |
|
| 42 |
st.markdown("---")
|
| 43 |
|
|
|
|
| 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 |
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}")
|
| 65 |
|
| 66 |
st.markdown("---")
|
| 67 |
|