39 lines
1.5 KiB
Java
39 lines
1.5 KiB
Java
public class CurrencyAnalyzer {
|
||
|
||
private static double lastValue = -1;
|
||
|
||
public static void analyze(double current) {
|
||
if (lastValue == -1) {
|
||
lastValue = current;
|
||
|
||
// Уведомление при запуске
|
||
String startMsg = "✅ <b>Мониторинг курса USD запущен</b>\n" +
|
||
"Текущий курс: <b>" + current + "</b> ₽";
|
||
TelegramNotifier.sendMessage(startMsg);
|
||
|
||
System.out.println("Начальное значение USD: " + current);
|
||
return;
|
||
}
|
||
|
||
String changeMsg = "";
|
||
if (current > lastValue) {
|
||
changeMsg = "📈 Курс доллара <b>вырос ↑</b>";
|
||
} else if (current < lastValue) {
|
||
changeMsg = "📉 Курс доллара <b>упал ↓</b>";
|
||
} else {
|
||
return; // без изменений — не спамим
|
||
}
|
||
|
||
// Уведомление в Telegram
|
||
String telegramMsg = changeMsg + "\n" +
|
||
"Было: <b>" + lastValue + "</b> ₽\n" +
|
||
"Стало: <b>" + current + "</b> ₽";
|
||
TelegramNotifier.sendMessage(telegramMsg);
|
||
|
||
// Вывод в консоль (чистый текст)
|
||
System.out.println(changeMsg.replace("<b>", "").replace("</b>", "") +
|
||
" (было " + lastValue + ", стало " + current + ")");
|
||
|
||
lastValue = current;
|
||
}
|
||
} |