35 lines
1.2 KiB
Java
35 lines
1.2 KiB
Java
public class CurrencyAnalyzer {
|
||
private static double last_value = -1;
|
||
|
||
public static void analyze(double current) {
|
||
if (last_value == -1) {
|
||
last_value = current;
|
||
|
||
String start_msg = "<b>Мониторинг курса USD запущен</b>\n" +
|
||
"Текущий курс: <b>" + current + "</b> ₽";
|
||
TelegramNotifier.sendMessage(start_msg);
|
||
|
||
System.out.println("Начальное значение USD: " + current);
|
||
return;
|
||
}
|
||
|
||
String msg = "";
|
||
if (current > last_value) {
|
||
msg = "Курс доллара <b>вырос ↑</b>";
|
||
} else if (current < last_value) {
|
||
msg = "Курс доллара <b>упал ↓</b>";
|
||
} else {
|
||
return;
|
||
}
|
||
|
||
String telegram_msg = msg + "\n" +
|
||
"Было: <b>" + last_value + "</b> ₽\n" +
|
||
"Стало: <b>" + current + "</b> ₽";
|
||
TelegramNotifier.sendMessage(telegram_msg);
|
||
|
||
System.out.println(msg.replace("<b>", "").replace("</b>", "") +
|
||
" (было " + last_value + ", стало " + current + ")");
|
||
|
||
last_value = current;
|
||
}
|
||
} |