Alexander Oh commited on
Commit
1479e0f
·
unverified ·
2 Parent(s): 29f340a d4fa864

Merge pull request #8 from alexoh2bd/Natalie

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +23 -1
src/streamlit_app.py CHANGED
@@ -161,7 +161,7 @@ def main():
161
  # Use custom query if provided
162
  final_query = custom_query if custom_query else selected_query
163
 
164
- # Time range
165
  days = st.sidebar.slider(
166
  "📅 Days to analyze:",
167
  min_value=1,
@@ -169,6 +169,11 @@ def main():
169
  value=7,
170
  help="How many days back to search for news"
171
  )
 
 
 
 
 
172
 
173
  # News sources from config
174
  news_sources = config["news_sources"]
@@ -212,6 +217,23 @@ def main():
212
  if 'df' in st.session_state and not st.session_state.df.empty:
213
  df = st.session_state.df
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  # ===== Summary Metrics =====
216
  st.markdown("### 📊 Analysis Summary")
217
  col1, col2, col3, col4 = st.columns(4)
 
161
  # Use custom query if provided
162
  final_query = custom_query if custom_query else selected_query
163
 
164
+ # Time range (days)
165
  days = st.sidebar.slider(
166
  "📅 Days to analyze:",
167
  min_value=1,
 
169
  value=7,
170
  help="How many days back to search for news"
171
  )
172
+
173
+ # Date range filter (optional, after data is loaded)
174
+ st.sidebar.markdown("---")
175
+ st.sidebar.markdown("#### Optional: Filter by Date Range")
176
+ date_range = None
177
 
178
  # News sources from config
179
  news_sources = config["news_sources"]
 
217
  if 'df' in st.session_state and not st.session_state.df.empty:
218
  df = st.session_state.df
219
 
220
+ # Date range filter UI (if date column exists)
221
+ if 'published_at' in df.columns:
222
+ min_date = pd.to_datetime(df['published_at']).min().date()
223
+ max_date = pd.to_datetime(df['published_at']).max().date()
224
+ start_date, end_date = st.sidebar.date_input(
225
+ "Select date range:",
226
+ value=(min_date, max_date),
227
+ min_value=min_date,
228
+ max_value=max_date
229
+ )
230
+ # Filter DataFrame by date range
231
+ mask = (pd.to_datetime(df['published_at']).dt.date >= start_date) & (pd.to_datetime(df['published_at']).dt.date <= end_date)
232
+ df = df.loc[mask]
233
+ if df.empty:
234
+ st.warning("No articles found in the selected date range.")
235
+ st.stop()
236
+
237
  # ===== Summary Metrics =====
238
  st.markdown("### 📊 Analysis Summary")
239
  col1, col2, col3, col4 = st.columns(4)