mirror of
https://github.com/Redume/Shirino.git
synced 2025-04-02 18:57:34 +03:00
Compare commits
3 commits
c9eb773f10
...
b5f75ef0bc
Author | SHA1 | Date | |
---|---|---|---|
b5f75ef0bc | |||
ef980f1ef6 | |||
db79e74268 |
3 changed files with 13 additions and 11 deletions
|
@ -58,7 +58,7 @@ class Converter:
|
|||
for key in ['terms', 'privacy', 'timestamp']:
|
||||
data.pop(key, None)
|
||||
|
||||
if len(data.get('to')) == 0:
|
||||
if not data.get('to'):
|
||||
raise RuntimeError('Failed to get the exchange rate from DuckDuckGo')
|
||||
|
||||
conv = data.get('to')[0]
|
||||
|
|
8
main.py
8
main.py
|
@ -78,12 +78,12 @@ async def currency(query: types.InlineQuery) -> None:
|
|||
)],
|
||||
query)
|
||||
|
||||
if not conv_currency or not from_currency:
|
||||
return await reply(result_id, [('The currency exchange rate could not be found.', None, None)], query)
|
||||
|
||||
conv.from_currency = from_currency.upper()
|
||||
conv.conv_currency = conv_currency.upper()
|
||||
await conv.convert()
|
||||
try:
|
||||
await conv.convert()
|
||||
except RuntimeError as e:
|
||||
return await reply(result_id, [('The currency exchange rate could not be determined', None, None)], query)
|
||||
|
||||
chart = await create_chart(from_currency, conv_currency)
|
||||
|
||||
|
|
|
@ -3,10 +3,12 @@ from decimal import Decimal
|
|||
def format_number(number):
|
||||
number = Decimal(str(number))
|
||||
|
||||
formatted_integer_part = '{:,.0f}'.format(number).replace(',', ' ')
|
||||
formatted_integer_part = '{:,.0f}'.format(number // 1).replace(',', ' ')
|
||||
fractional_part = f"{number % 1:.30f}".split('.')[1]
|
||||
|
||||
if '.' in str(number):
|
||||
fractional_part = str(number).split('.')[1][:3]
|
||||
return formatted_integer_part + '.' + fractional_part
|
||||
else:
|
||||
return formatted_integer_part
|
||||
if int(fractional_part) == 0:
|
||||
return formatted_integer_part + ''
|
||||
|
||||
significant_start = next((i for i, char in enumerate(fractional_part) if char != '0'), len(fractional_part))
|
||||
result_fractional = fractional_part[:significant_start + 3]
|
||||
return formatted_integer_part + '.' + result_fractional
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue