tg_bot/msg/ExchangeMsg.py
2024-12-06 14:20:29 +03:00

36 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from bot.DaMsg import DaMsg
from exchange.Cbr import Cbr
class ExchangeMsg(DaMsg):
@staticmethod
def get_msg(data=None) -> str:
if data is None:
data = {}
cbr = Cbr()
currencies = cbr.get_by_codes()
msg = '📈 Курс валют ЦБ РФ на сегодня:\n\n'
for currency in currencies:
circle = ExchangeMsg.get_circle(currency['Value'], currency['Previous'])
arrow = ExchangeMsg.get_arrow(currency['Value'], currency['Previous'])
msg = msg + "{n}: {c} <b>{v}</b> {a}\n\n".format(n=currency['Name'], c=circle, v=currency['Value'], a=arrow)
msg = msg + "&#128073; <a href='https://t.me/prosmi_bot'>Предложить новость</a>"
return msg
@staticmethod
def get_arrow(value, previous) -> str:
if value > previous:
return "&#11014;"
return "&#11015;"
@staticmethod
def get_circle(value, previous) -> str:
if value > previous:
return "&#128994;"
return "&#128308;"