package src;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
public class ParseInfoСurrency {
private static Document getPageUSD() throws IOException {
String url = "https://nationalbank.kz/ru/exchangerates/ezhednevnye-oficialnye-rynochnye-kursy-valyut/report?rates%5B%5D=5&beginDate";
org.jsoup.nodes.Document page = Jsoup.parse(new URL(url), 10000);
return page;
}
private static Document getPageRUB() throws IOException {
String url = "https://nationalbank.kz/ru/exchangerates/ezhednevnye-oficialnye-rynochnye-kursy-valyut/report?rates%5B%5D=16&beginDate";
Document page = Jsoup.parse(new URL(url), 10000);
return page;
}
private static Document getPageEUR() throws IOException {
String url = "https://nationalbank.kz/ru/exchangerates/ezhednevnye-oficialnye-rynochnye-kursy-valyut/report?rates%5B%5D=6&beginDate";
Document page = Jsoup.parse(new URL(url), 10000);
return page;
}
ArrayList<String> pageCount = new ArrayList<>();
private static String parseText(Elements names) {
String arrayList = "";
String temp = "";
int index = 0;
for (Element name : names) {
String value = name.select("td").text();
if (value.equals("1")) {
continue;
}
index++;
if (index == 1) {
temp = value;
}
else {
temp += " - " + value + ".тг" + "\n" ;
index = 0;
arrayList += temp;
}
}
return arrayList;
}
public String eurGetName() throws Exception {
Document eurPage = getPageEUR();
Elements tableEurKzt = eurPage.select("table[class = table table-bordered table-striped text-size-xs]");
Elements names = tableEurKzt.select("td");
return parseText(names);
}
public String rubGetName() throws Exception {
Document rubPage = getPageRUB();
Elements tableRubKzt = rubPage.select("table[class = table table-bordered table-striped text-size-xs]");
Elements names = tableRubKzt.select("td");
return parseText(names);
}
public String usdGetName() throws Exception {
Document usdPage = getPageUSD();
Elements tableUsdKzt = usdPage.select("table[class = table table-bordered table-striped text-size-xs]");
Elements names = tableUsdKzt.select("td");
return parseText(names);
}
}