CodexFlow_TM / web_ingest.py
LordXido's picture
Update web_ingest.py
46c627f verified
raw
history blame contribute delete
641 Bytes
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],
}