def moneyconvert(self, amount: float, base: str, to: str):
"""Currency converter
Set the amount, currency FROM (base) and currency TO
Available currencies for conversion:
AUD BGN BRL CAD CHF CNY CZK DKK EUR GBP HKD HRK HUF IDR ILS INR JPY KRW MXN MYR NOK NZD PHP PLN RON RUB SEK SGD THB TRY USD ZAR
***WARNING***
Conversion may not be exact"""
if base.upper() not in self.currencies or to.upper() not in self.currencies:
await self.bot.say('One or both of the currencies selected are invalid')
else:
api = 'http://api.fixer.io/latest?base={}'.format(base.upper())
async with aiohttp.request("GET", api) as r:
result = await r.json()
rate = result['rates'][to.upper()]
converted_amount = amount * rate
pre_conv = '{0:.2f}'.format(amount)
post_conv = '{0:.2f}'.format(converted_amount)
await self.bot.say('`{} {} = {} {}`'.format(base.upper(), pre_conv, to.upper(), post_conv))
评论列表
文章目录