File size: 730 Bytes
978871d a66d267 5742f0d a66d267 978871d a66d267 978871d a66d267 978871d a66d267 978871d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from fastapi import FastAPI, Query
from forex_python.converter import CurrencyRates
app = FastAPI()
currency_rates = CurrencyRates()
@app.get("/convert/")
def convert_currency(amount: float = Query(..., description="Quantia a ser convertida"),
from_currency: str = Query(..., description="Moeda de origem"),
to_currency: str = Query(..., description="Moeda de destino")):
"""
Converte uma quantia de uma moeda para outra.
"""
converted_amount = currency_rates.convert(from_currency, to_currency, amount)
return {
"amount": amount,
"from_currency": from_currency,
"to_currency": to_currency,
"converted_amount": converted_amount
} |