Commit
Β·
86fdee3
1
Parent(s):
1479e0f
Fixed date range
Browse files- src/api_handler.py +6 -4
- src/streamlit_app.py +22 -22
src/api_handler.py
CHANGED
|
@@ -26,7 +26,7 @@ class AINewsAnalyzer:
|
|
| 26 |
|
| 27 |
def fetch_ai_news(self,
|
| 28 |
query: str = "artificial intelligence",
|
| 29 |
-
days: int = 7,
|
| 30 |
language: str = "en",
|
| 31 |
sources: Optional[str] = None,
|
| 32 |
page_size: int = 100) -> List[Dict]:
|
|
@@ -44,9 +44,11 @@ class AINewsAnalyzer:
|
|
| 44 |
List of news articles with metadata
|
| 45 |
"""
|
| 46 |
# Calculate date range
|
| 47 |
-
|
| 48 |
-
from_date =
|
|
|
|
| 49 |
|
|
|
|
| 50 |
# Prepare API parameters
|
| 51 |
params = {
|
| 52 |
'q': query,
|
|
@@ -192,7 +194,7 @@ class AINewsAnalyzer:
|
|
| 192 |
|
| 193 |
def get_ai_news_with_sentiment(self,
|
| 194 |
query: str = "artificial intelligence",
|
| 195 |
-
days: int = 7,
|
| 196 |
sources: Optional[str] = None,
|
| 197 |
model: str = "Textblob") -> pd.DataFrame:
|
| 198 |
"""
|
|
|
|
| 26 |
|
| 27 |
def fetch_ai_news(self,
|
| 28 |
query: str = "artificial intelligence",
|
| 29 |
+
days: tuple[int] = (7,14),
|
| 30 |
language: str = "en",
|
| 31 |
sources: Optional[str] = None,
|
| 32 |
page_size: int = 100) -> List[Dict]:
|
|
|
|
| 44 |
List of news articles with metadata
|
| 45 |
"""
|
| 46 |
# Calculate date range
|
| 47 |
+
today = datetime.now()
|
| 48 |
+
from_date = today - timedelta(days=days[0]) # 7
|
| 49 |
+
to_date = today - timedelta(days=days[1]) # 14
|
| 50 |
|
| 51 |
+
print(from_date, to_date)
|
| 52 |
# Prepare API parameters
|
| 53 |
params = {
|
| 54 |
'q': query,
|
|
|
|
| 194 |
|
| 195 |
def get_ai_news_with_sentiment(self,
|
| 196 |
query: str = "artificial intelligence",
|
| 197 |
+
days: tuple[int] = (7,14),
|
| 198 |
sources: Optional[str] = None,
|
| 199 |
model: str = "Textblob") -> pd.DataFrame:
|
| 200 |
"""
|
src/streamlit_app.py
CHANGED
|
@@ -166,14 +166,14 @@ def main():
|
|
| 166 |
"π
Days to analyze:",
|
| 167 |
min_value=1,
|
| 168 |
max_value=30,
|
| 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 |
-
|
| 177 |
|
| 178 |
# News sources from config
|
| 179 |
news_sources = config["news_sources"]
|
|
@@ -198,7 +198,7 @@ def main():
|
|
| 198 |
# Load data
|
| 199 |
if st.sidebar.button("π Analyze News", type="primary"):
|
| 200 |
with st.spinner(f"Fetching and analyzing news about '{final_query}'..."):
|
| 201 |
-
df, error = load_news_data(final_query, days, sources=sources, model=model_query)
|
| 202 |
|
| 203 |
if error:
|
| 204 |
st.error(f"Error loading data: {error}")
|
|
@@ -217,22 +217,22 @@ def main():
|
|
| 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 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
|
| 237 |
# ===== Summary Metrics =====
|
| 238 |
st.markdown("### π Analysis Summary")
|
|
|
|
| 166 |
"π
Days to analyze:",
|
| 167 |
min_value=1,
|
| 168 |
max_value=30,
|
| 169 |
+
value=(7,14),
|
| 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 |
+
|
| 177 |
|
| 178 |
# News sources from config
|
| 179 |
news_sources = config["news_sources"]
|
|
|
|
| 198 |
# Load data
|
| 199 |
if st.sidebar.button("π Analyze News", type="primary"):
|
| 200 |
with st.spinner(f"Fetching and analyzing news about '{final_query}'..."):
|
| 201 |
+
df, error = load_news_data(final_query, days=days, sources=sources, model=model_query)
|
| 202 |
|
| 203 |
if error:
|
| 204 |
st.error(f"Error loading data: {error}")
|
|
|
|
| 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")
|