Spaces:
Running
Running
Sync from GitHub
Browse files- app/data_manager.py +40 -3
app/data_manager.py
CHANGED
|
@@ -235,14 +235,51 @@ def ingest_news(session: Session) -> dict:
|
|
| 235 |
Returns:
|
| 236 |
Dict with stats: imported, duplicates, language_filtered, fuzzy_filtered
|
| 237 |
"""
|
|
|
|
|
|
|
| 238 |
settings = get_settings()
|
| 239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
stats = {
|
| 241 |
"imported": 0,
|
| 242 |
"duplicates": 0,
|
| 243 |
"language_filtered": 0,
|
| 244 |
"fuzzy_filtered": 0,
|
| 245 |
"source": "unknown",
|
|
|
|
| 246 |
}
|
| 247 |
|
| 248 |
# Collect articles from sources
|
|
@@ -252,7 +289,7 @@ def ingest_news(session: Session) -> dict:
|
|
| 252 |
if settings.newsapi_key:
|
| 253 |
articles = fetch_newsapi_articles(
|
| 254 |
api_key=settings.newsapi_key,
|
| 255 |
-
query=
|
| 256 |
language=settings.news_language,
|
| 257 |
lookback_days=settings.lookback_days,
|
| 258 |
)
|
|
@@ -260,10 +297,10 @@ def ingest_news(session: Session) -> dict:
|
|
| 260 |
all_articles.extend(articles)
|
| 261 |
stats["source"] = "newsapi"
|
| 262 |
|
| 263 |
-
# RSS fallback/supplement
|
| 264 |
if not all_articles or not settings.newsapi_key:
|
| 265 |
rss_articles = fetch_google_news(
|
| 266 |
-
query=
|
| 267 |
language=settings.news_language,
|
| 268 |
)
|
| 269 |
all_articles.extend(rss_articles)
|
|
|
|
| 235 |
Returns:
|
| 236 |
Dict with stats: imported, duplicates, language_filtered, fuzzy_filtered
|
| 237 |
"""
|
| 238 |
+
import random
|
| 239 |
+
|
| 240 |
settings = get_settings()
|
| 241 |
|
| 242 |
+
# Strategic queries based on S&P Global 2026 copper market report
|
| 243 |
+
# Each pipeline run focuses on different strategic topics for diversity
|
| 244 |
+
STRATEGIC_QUERIES = [
|
| 245 |
+
# Supply Crisis / Deficit Focus
|
| 246 |
+
"copper supply deficit 2026",
|
| 247 |
+
"copper shortage AI data center",
|
| 248 |
+
"copper inventory LME warehouse",
|
| 249 |
+
|
| 250 |
+
# Key Players (Majors & Producers)
|
| 251 |
+
"Freeport-McMoRan copper outlook",
|
| 252 |
+
"BHP copper production news",
|
| 253 |
+
"Rio Tinto copper investment",
|
| 254 |
+
"Southern Copper SCCO forecast",
|
| 255 |
+
|
| 256 |
+
# China & Emerging Markets
|
| 257 |
+
"Zijin Mining copper investment",
|
| 258 |
+
"China copper demand stimulus",
|
| 259 |
+
"copper demand EV battery",
|
| 260 |
+
|
| 261 |
+
# M&A & Strategic Moves
|
| 262 |
+
"copper mining acquisition merger",
|
| 263 |
+
"Ivanhoe Mines copper grade",
|
| 264 |
+
"Lundin Mining copper deal",
|
| 265 |
+
|
| 266 |
+
# Price & Macro Analysis
|
| 267 |
+
"copper price forecast Goldman Sachs",
|
| 268 |
+
"copper futures CME analysis",
|
| 269 |
+
"grade decline copper mining",
|
| 270 |
+
]
|
| 271 |
+
|
| 272 |
+
# Select a random strategic query for this run (ensures diversity over time)
|
| 273 |
+
strategic_query = random.choice(STRATEGIC_QUERIES)
|
| 274 |
+
logger.info(f"🕵️ Strategic News Agent: Investigating '{strategic_query}'")
|
| 275 |
+
|
| 276 |
stats = {
|
| 277 |
"imported": 0,
|
| 278 |
"duplicates": 0,
|
| 279 |
"language_filtered": 0,
|
| 280 |
"fuzzy_filtered": 0,
|
| 281 |
"source": "unknown",
|
| 282 |
+
"query_used": strategic_query,
|
| 283 |
}
|
| 284 |
|
| 285 |
# Collect articles from sources
|
|
|
|
| 289 |
if settings.newsapi_key:
|
| 290 |
articles = fetch_newsapi_articles(
|
| 291 |
api_key=settings.newsapi_key,
|
| 292 |
+
query=strategic_query,
|
| 293 |
language=settings.news_language,
|
| 294 |
lookback_days=settings.lookback_days,
|
| 295 |
)
|
|
|
|
| 297 |
all_articles.extend(articles)
|
| 298 |
stats["source"] = "newsapi"
|
| 299 |
|
| 300 |
+
# RSS fallback/supplement - also use strategic query
|
| 301 |
if not all_articles or not settings.newsapi_key:
|
| 302 |
rss_articles = fetch_google_news(
|
| 303 |
+
query=strategic_query,
|
| 304 |
language=settings.news_language,
|
| 305 |
)
|
| 306 |
all_articles.extend(rss_articles)
|