Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,3 +61,15 @@ async def convert_currency(amount: float, from_currency: str, to_currency: str):
|
|
| 61 |
return {"converted_amount": converted_amount}
|
| 62 |
except KeyError:
|
| 63 |
return {"error": "Invalid currency code"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
return {"converted_amount": converted_amount}
|
| 62 |
except KeyError:
|
| 63 |
return {"error": "Invalid currency code"}
|
| 64 |
+
|
| 65 |
+
@app.get("/supported-currencies")
|
| 66 |
+
async def get_supported_currencies():
|
| 67 |
+
"""Endpoint to return the list of supported currencies."""
|
| 68 |
+
rates = get_cached_rates()
|
| 69 |
+
|
| 70 |
+
if "error" in rates:
|
| 71 |
+
return {"error": "Failed to fetch exchange rates"}
|
| 72 |
+
|
| 73 |
+
# Extract the keys (currency codes) from the conversion_rates field
|
| 74 |
+
supported_currencies = list(rates["conversion_rates"].keys())
|
| 75 |
+
return {"currencies": supported_currencies}
|