Spaces:
Sleeping
Sleeping
File size: 870 Bytes
c165904 | 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 26 27 28 29 30 31 32 33 34 | import requests
from public_data_sources import WORLD_BANK_BASE, INDICATORS
def fetch_world_bank_indicator(
country="WLD",
indicator="NY.GDP.MKTP.CD",
year="2022"
):
url = (
f"{WORLD_BANK_BASE}/country/{country}/indicator/"
f"{indicator}?format=json&per_page=1&date={year}"
)
try:
response = requests.get(url, timeout=10)
data = response.json()
value = data[1][0]["value"]
return value
except Exception:
return None
def fetch_macro_anchor():
return {
"global_gdp": fetch_world_bank_indicator(
indicator=INDICATORS["GDP"]
),
"global_inflation": fetch_world_bank_indicator(
indicator=INDICATORS["INFLATION"]
),
"population": fetch_world_bank_indicator(
indicator=INDICATORS["POPULATION"]
),
} |