File size: 641 Bytes
3eddc20
 
 
46c627f
3eddc20
 
 
46c627f
 
 
 
 
3eddc20
46c627f
3eddc20
46c627f
3eddc20
46c627f
3eddc20
46c627f
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import requests
from datetime import datetime

PUBLIC_ENDPOINTS = {
    "gold_price": "https://api.metals.live/v1/spot/gold",
}

NEWS_ENDPOINTS = [
    "https://newsapi.org/v2/top-headlines?category=business&pageSize=20&apiKey=demo"
]

def fetch_json(url):
    try:
        r = requests.get(url, timeout=5)
        r.raise_for_status()
        return r.json()
    except Exception as e:
        return {"error": str(e)}

def ingest():
    return {
        "timestamp": datetime.utcnow().isoformat(),
        "prices": {k: fetch_json(v) for k, v in PUBLIC_ENDPOINTS.items()},
        "news": [fetch_json(url) for url in NEWS_ENDPOINTS],
    }