first
This commit is contained in:
35
CurrencyAnalyzer.java
Normal file
35
CurrencyAnalyzer.java
Normal file
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user