This documentation details the news_scraper.py script, an advanced automated pipeline designed to fetch, parse, and semantically enrich global macro-financial news for vector database (Qdrant) ingestion.
The pipeline acts as a real-time intelligence gathering engine for a Gold/Silver options trading desk. It aggregates global news from the GDELT project, scrapes the full article text, and utilizes a local Large Language Model (Llama 3) to translate foreign text, filter out noise, and generate quantitative metrics (like sentiment/tone scores and volatility implications) to feed into an AI-driven trading or RAG system.
- Topic-bucketed news (central banks, inflation/employment, yields/USD, geopolitics, precious metals spot, metals derivatives) via GDELT queries over the last 48 hours.
- Full article text where scraping succeeds (
newspaper3k), with DuckDuckGo → Yahoo Finance fallback for alternate URLs. - LLM-enriched signals (local Llama 3 via
ChatOllama): English title, dense summary, tone score for gold/silver (−5…+5), entities, impacted asset classes, and VIX/volatility implication.
-
Topic definition and querying (ingestion)
- Predefined boolean search logic for macro drivers (Central Banks, Inflation, Geopolitics) and asset-specific news (Gold/Silver spot and derivatives).
- GDELT 2.0 API for the latest global article metadata over the past 48 hours.
-
Resilient scraping and deduplication
- Dedup via URL slugs and cleaned titles.
newspaper3kfor full raw text.- On failure, DuckDuckGo Search (DDGS) targeting Yahoo Finance for an alternate URL.
-
LLM extraction and scoring (enrichment)
- Local Llama 3 (
ChatOllama) with a strict zero-temperature quantitative analyst prompt. - Non-English content translated to English.
- Invalid content filtered (cookie walls, 404s).
- Dense summaries, entities, and market impact metrics extracted.
- Local Llama 3 (
-
Formatting and archival (export)
- Qdrant-compatible JSON structure.
- Raw data, full-text backups, and vector-ready payloads under daily directories.
- Topic loop: For each entry in
ALL_TOPICS(macro + asset queries), call GDELTdocAPI (mode=artlist,maxrecords=10,sort=DateDesc). - Dedup: Signatures from URL slug or cleaned title to avoid duplicate articles.
- Raw append: Write GDELT article JSON lines to Bronze raw file.
- Scrape: For each article, fetch full text; on failure skip (no full-text / Qdrant line).
- LLM: Structured prompt extracts fields; invalid or junk content discarded when parser finds no valid
SUMMARY. - Export: Append full-text JSONL and Qdrant JSONL per topic.
| Item | Detail |
|---|---|
| Inputs | Hardcoded queries in MACRO_TOPICS and ASSET_TOPICS. APIs: GDELT https://api.gdeltproject.org/api/v2/doc/doc. Local: Ollama llama3 (default ChatOllama endpoint). No JSON config file on disk. |
| Update frequency | Daily per collect_data.py (07:00). |
| Stream | Path |
|---|---|
| Raw GDELT | Data/1_Bronze_Raw/News_Scrapes/{YYYY-MM-DD}/Raw/raw_gdelt_{topic_name}.jsonl |
| Full text | Data/1_Bronze_Raw/News_Scrapes/{YYYY-MM-DD}/Full_text/full_text_{topic_name}.jsonl |
| Qdrant-ready | Data/3_Gold_Semantic/News_Qdrant/{YYYY-MM-DD}/qdrant_{topic_name}_processed.jsonl |
| Logs | logs/{YYYY-MM-DD}/scraper_{YYYY-MM-DD}.log |
Topic keys (topic_name): macro_central_banks, macro_inflation_employment, macro_yields_dollar, macro_geopolitics_risk, asset_precious_metals_spot, asset_metals_derivatives.
Each line is the JSON object returned by GDELT for an article (fields such as url, title, domain, urldatetime as provided by the API).
| Field | Description |
|---|---|
url |
Article URL |
title |
Title from GDELT |
publish_date |
From urldatetime or fallback ISO time |
full_text |
Scraped body text |
| Field | Description | Type |
|---|---|---|
id |
A unique UUID v5 generated deterministically from the article URL. | String |
text |
The clean string to be embedded. Format: "{english_title}. {dense_summary}". |
String |
metadata |
A nested dictionary containing structured tags for Qdrant payload filtering. | Object |
| Key | Description | Type |
|---|---|---|
topic |
The internal category that triggered the fetch (e.g., macro_central_banks). |
String |
title |
The English-translated article title. | String |
original_title |
The native/original title fetched from GDELT. | String |
publish_date |
The ISO-8601 formatted publication timestamp. | String |
publish_timestamp |
Integer Unix epoch for fast time-range filtering in the vector DB. | Integer |
source |
The domain name of the publisher. | String |
url |
Direct link to the source article. | String |
entities |
Array of 3-5 explicitly mentioned key entities/organizations. | Array of Strings |
impacted_assets |
Broad asset classes affected by the news (e.g., USD, Gold, Equities). | Array of Strings |
volatility_implication |
Estimated impact on market fear/VIX (Increase, Decrease, Neutral). |
String |
llm_tone_score |
Quantitative sentiment score on Gold/Silver from -5 (Bearish) to +5 (Bullish). | Integer |
pip install requests newspaper3k duckduckgo-search langchain-ollamaAlso requires a running Ollama server with the llama3 model available.