38 lines
1.2 KiB
Java
38 lines
1.2 KiB
Java
public class Main {
|
||
public static void main(String[] args) {
|
||
String bot_token = System.getenv("BOT_TOKEN");
|
||
String chat_id = System.getenv("CHAT_ID");
|
||
|
||
if (bot_token == null || bot_token.isBlank() || chat_id == null || chat_id.isBlank()) {
|
||
System.err.println("Не найдены environment BOT_TOKEN и CHAT_ID");
|
||
return;
|
||
}
|
||
|
||
TelegramNotifier.init(bot_token, chat_id);
|
||
System.out.println("Telegram-уведомления работают.");
|
||
|
||
String url = "https://cbr.ru/currency_base/daily/";
|
||
|
||
while (true) {
|
||
try {
|
||
String html = WebLoader.loadPage(url);
|
||
|
||
double usd = CurrencyParser.parseUSD(html);
|
||
|
||
if (usd != -1) {
|
||
System.out.println("USD: " + usd);
|
||
|
||
CsvWriter.write(usd);
|
||
CurrencyAnalyzer.analyze(usd);
|
||
} else {
|
||
System.err.println("Не удалось спарсить курс USD");
|
||
}
|
||
|
||
Thread.sleep(60 * 1000);
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
}
|
||
} |