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