refactor, new data loading
This commit is contained in:
parent
18a584f6d8
commit
05425c0d04
@ -2,8 +2,9 @@ package cz.kamma.mining;
|
|||||||
|
|
||||||
public interface Constants {
|
public interface Constants {
|
||||||
|
|
||||||
public static final String APP_VERSION = "v0.8";
|
public static final String APP_VERSION = "v0.9";
|
||||||
public static final String COPYRIGHT = "2021";
|
public static final String COPYRIGHT = "2021";
|
||||||
public static final int DEFAULT_HTTP_TIMEOUT = 10000;
|
public static final int DEFAULT_HTTP_CONNECTION_TIMEOUT = 6000;
|
||||||
public static final int RELOAD_TIME = DEFAULT_HTTP_TIMEOUT;
|
public static final int DEFAULT_HTTP_READ_TIMEOUT = 18000;
|
||||||
|
public static final int RELOAD_TIME = 25000;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
package cz.kamma.mining.bean;
|
package cz.kamma.mining.bean;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -13,7 +17,6 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import cz.kamma.mining.Constants;
|
import cz.kamma.mining.Constants;
|
||||||
import cz.kamma.mining.helper.HttpHelper;
|
|
||||||
import cz.kamma.mining.vo.KeyValue;
|
import cz.kamma.mining.vo.KeyValue;
|
||||||
|
|
||||||
public class MiningBean {
|
public class MiningBean {
|
||||||
@ -27,6 +30,7 @@ public class MiningBean {
|
|||||||
String currency;
|
String currency;
|
||||||
String resultStr;
|
String resultStr;
|
||||||
String restRequest;
|
String restRequest;
|
||||||
|
int finished = 0;
|
||||||
|
|
||||||
public String updateAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
public String updateAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||||
@ -58,8 +62,7 @@ public class MiningBean {
|
|||||||
|
|
||||||
for (int i = 0; i < cryptoCur.length; i++) {
|
for (int i = 0; i < cryptoCur.length; i++) {
|
||||||
String ccur = cryptoCur[i];
|
String ccur = cryptoCur[i];
|
||||||
restRequest = HttpHelper
|
restRequest = getStringResponse("https://www.bitstamp.net/api/v2/ticker/".concat(ccur).concat(currency));
|
||||||
.getStringResponse("https://www.bitstamp.net/api/v2/ticker/".concat(ccur).concat(currency));
|
|
||||||
if (restRequest != null && restRequest.length() > 0) {
|
if (restRequest != null && restRequest.length() > 0) {
|
||||||
JSONObject tmp = new JSONObject(restRequest);
|
JSONObject tmp = new JSONObject(restRequest);
|
||||||
double res = tmp.getDouble("last");
|
double res = tmp.getDouble("last");
|
||||||
@ -79,9 +82,10 @@ public class MiningBean {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) {
|
if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) {
|
||||||
restRequest = HttpHelper
|
restRequest = getStringResponse(
|
||||||
.getStringResponse("https://chain.so/api/v2/get_address_balance/LTC/".concat(ltcWallet));
|
"https://chain.so/api/v2/get_address_balance/LTC/".concat(ltcWallet));
|
||||||
if (restRequest != null && restRequest.length() > 0) {
|
if (restRequest != null && restRequest.length() > 0) {
|
||||||
JSONObject full = new JSONObject(restRequest);
|
JSONObject full = new JSONObject(restRequest);
|
||||||
JSONObject data = (JSONObject) full.get("data");
|
JSONObject data = (JSONObject) full.get("data");
|
||||||
@ -98,6 +102,10 @@ public class MiningBean {
|
|||||||
prices.add(wi);
|
prices.add(wi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
finished = finished | 1;
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
@ -105,8 +113,9 @@ public class MiningBean {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
if (xrpWallet != null && !"null".equals(xrpWallet) && xrpWallet.length() > 0) {
|
if (xrpWallet != null && !"null".equals(xrpWallet) && xrpWallet.length() > 0) {
|
||||||
restRequest = HttpHelper.getStringResponse(
|
restRequest = getStringResponse(
|
||||||
"https://data.ripple.com/v2/accounts/".concat(xrpWallet).concat("/balances"));
|
"https://data.ripple.com/v2/accounts/".concat(xrpWallet).concat("/balances"));
|
||||||
if (restRequest != null && restRequest.length() > 0) {
|
if (restRequest != null && restRequest.length() > 0) {
|
||||||
JSONObject full = new JSONObject(restRequest);
|
JSONObject full = new JSONObject(restRequest);
|
||||||
@ -122,6 +131,10 @@ public class MiningBean {
|
|||||||
prices.add(wi);
|
prices.add(wi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
finished = finished | 10;
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
@ -129,10 +142,11 @@ public class MiningBean {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
if (ethWallet != null && !"null".equals(ethWallet) && ethWallet.length() > 0) {
|
if (ethWallet != null && !"null".equals(ethWallet) && ethWallet.length() > 0) {
|
||||||
restRequest = HttpHelper
|
restRequest = getStringResponse(
|
||||||
.getStringResponse("https://api.etherscan.io/api?module=account&action=balance&address="
|
"https://api.etherscan.io/api?module=account&action=balance&address=" + ethWallet
|
||||||
+ ethWallet + "&tag=latest&apikey=N54NVXSVSISMQ4QIM2JVKJW56KHCKMU5T4");
|
+ "&tag=latest&apikey=N54NVXSVSISMQ4QIM2JVKJW56KHCKMU5T4");
|
||||||
if (restRequest != null && restRequest.length() > 0) {
|
if (restRequest != null && restRequest.length() > 0) {
|
||||||
JSONObject full = new JSONObject(restRequest);
|
JSONObject full = new JSONObject(restRequest);
|
||||||
String confirmedBalance = (String) full.get("result");
|
String confirmedBalance = (String) full.get("result");
|
||||||
@ -149,6 +163,10 @@ public class MiningBean {
|
|||||||
prices.add(wi);
|
prices.add(wi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
finished = finished | 100;
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
@ -156,12 +174,14 @@ public class MiningBean {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
if (ltcapikey != null && !"null".equals(ltcapikey) && ltcapikey.length() > 0) {
|
if (ltcapikey != null && !"null".equals(ltcapikey) && ltcapikey.length() > 0) {
|
||||||
String miningJson = HttpHelper
|
String miningJson = getStringResponse(
|
||||||
.getStringResponse("https://www.litecoinpool.org/api?api_key=".concat(ltcapikey));
|
"https://www.litecoinpool.org/api?api_key=".concat(ltcapikey));
|
||||||
if (miningJson != null && miningJson.length() > 0) {
|
if (miningJson != null && miningJson.length() > 0) {
|
||||||
JSONObject full = new JSONObject(miningJson);
|
JSONObject full = new JSONObject(miningJson);
|
||||||
JSONObject user = (JSONObject) full.get("user");
|
JSONObject user = (JSONObject) full.get("user");
|
||||||
|
|
||||||
KeyValue wi = new KeyValue();
|
KeyValue wi = new KeyValue();
|
||||||
wi.setKey("HashRate");
|
wi.setKey("HashRate");
|
||||||
if (user.getInt("hash_rate") > 0)
|
if (user.getInt("hash_rate") > 0)
|
||||||
@ -210,8 +230,8 @@ public class MiningBean {
|
|||||||
wi = new KeyValue();
|
wi = new KeyValue();
|
||||||
wi.setKey("Expected 24h");
|
wi.setKey("Expected 24h");
|
||||||
if (user.getDouble("expected_24h_rewards") > 0)
|
if (user.getDouble("expected_24h_rewards") > 0)
|
||||||
wi.setValue(user.getDouble("expected_24h_rewards") + " LTC " + curSym
|
wi.setValue(user.getDouble("expected_24h_rewards") + " LTC " + curSym + String
|
||||||
+ String.format("%.2f", (user.getDouble("expected_24h_rewards") * lastPrices[1])));
|
.format("%.2f", (user.getDouble("expected_24h_rewards") * lastPrices[1])));
|
||||||
else
|
else
|
||||||
wi.setValue("Unknown");
|
wi.setValue("Unknown");
|
||||||
workers.add(wi);
|
workers.add(wi);
|
||||||
@ -284,6 +304,10 @@ public class MiningBean {
|
|||||||
pool.add(wi);
|
pool.add(wi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
finished = finished | 1000;
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
@ -293,9 +317,10 @@ public class MiningBean {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String miningJson = HttpHelper
|
try {
|
||||||
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserworkers&api_key="
|
String miningJson = getStringResponse(
|
||||||
+ dogapikey + "&id=282608&_=1621333944761", 5000);
|
"https://aikapool.com/doge/index.php?page=api&action=getuserworkers&api_key="
|
||||||
|
+ dogapikey + "&id=282608&_=1621333944761");
|
||||||
if (miningJson != null && miningJson.length() > 0) {
|
if (miningJson != null && miningJson.length() > 0) {
|
||||||
JSONObject full = new JSONObject(miningJson);
|
JSONObject full = new JSONObject(miningJson);
|
||||||
JSONObject user = (JSONObject) full.get("getuserworkers");
|
JSONObject user = (JSONObject) full.get("getuserworkers");
|
||||||
@ -311,6 +336,10 @@ public class MiningBean {
|
|||||||
workers.add(wi);
|
workers.add(wi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
finished = finished | 10000;
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
@ -318,9 +347,10 @@ public class MiningBean {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String miningJson = HttpHelper
|
try {
|
||||||
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getdashboarddata&api_key="
|
String miningJson = getStringResponse(
|
||||||
+ dogapikey + "&id=282608&_=1621333944761", 5000);
|
"https://aikapool.com/doge/index.php?page=api&action=getdashboarddata&api_key="
|
||||||
|
+ dogapikey + "&id=282608&_=1621333944761");
|
||||||
if (miningJson != null && miningJson.length() > 0) {
|
if (miningJson != null && miningJson.length() > 0) {
|
||||||
JSONObject full = new JSONObject(miningJson);
|
JSONObject full = new JSONObject(miningJson);
|
||||||
JSONObject user = (JSONObject) full.get("getdashboarddata");
|
JSONObject user = (JSONObject) full.get("getdashboarddata");
|
||||||
@ -396,6 +426,10 @@ public class MiningBean {
|
|||||||
wi.setValue("Unknown");
|
wi.setValue("Unknown");
|
||||||
network.add(wi);
|
network.add(wi);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
finished = finished | 100000;
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
@ -403,9 +437,10 @@ public class MiningBean {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String miningJson = HttpHelper
|
try {
|
||||||
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserbalance&api_key="
|
String miningJson = getStringResponse(
|
||||||
+ dogapikey + "&id=282608&_=1621333944761", 5000);
|
"https://aikapool.com/doge/index.php?page=api&action=getuserbalance&api_key="
|
||||||
|
+ dogapikey + "&id=282608&_=1621333944761");
|
||||||
if (miningJson != null && miningJson.length() > 0) {
|
if (miningJson != null && miningJson.length() > 0) {
|
||||||
JSONObject full = new JSONObject(miningJson);
|
JSONObject full = new JSONObject(miningJson);
|
||||||
JSONObject user = (JSONObject) full.get("getuserbalance");
|
JSONObject user = (JSONObject) full.get("getuserbalance");
|
||||||
@ -435,13 +470,20 @@ public class MiningBean {
|
|||||||
else
|
else
|
||||||
wi.setValue("Unknown");
|
wi.setValue("Unknown");
|
||||||
workers.add(wi);
|
workers.add(wi);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
finished = finished | 1000000;
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(Constants.DEFAULT_HTTP_TIMEOUT);
|
while (finished != 1042431) {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
finished = 0;
|
||||||
|
|
||||||
KeyValue wi = new KeyValue();
|
KeyValue wi = new KeyValue();
|
||||||
wi.setKey("Last Update");
|
wi.setKey("Last Update");
|
||||||
@ -497,4 +539,41 @@ public class MiningBean {
|
|||||||
return (days > 0 ? days + "d " : "") + (hours > 0 ? hours + "h " : "") + (mins > 0 ? mins + "m " : "");
|
return (days > 0 ? days + "d " : "") + (hours > 0 ? hours + "h " : "") + (mins > 0 ? mins + "m " : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getStringResponse(String urlStr) {
|
||||||
|
return getStringResponse(urlStr, Constants.DEFAULT_HTTP_CONNECTION_TIMEOUT, Constants.DEFAULT_HTTP_READ_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringResponse(String urlStr, int timeout, int readTimeout) {
|
||||||
|
String output = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
URL url = new URL(urlStr);
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setDoInput(true);
|
||||||
|
conn.setDoOutput(false);
|
||||||
|
conn.setConnectTimeout(timeout);
|
||||||
|
conn.setReadTimeout(readTimeout);
|
||||||
|
conn.setRequestProperty("User-Agent",
|
||||||
|
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36");
|
||||||
|
conn.connect();
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
while ((inputLine = in.readLine()) != null)
|
||||||
|
output += inputLine;
|
||||||
|
in.close();
|
||||||
|
conn.disconnect();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Error while getting HTTP response from " + urlStr + ". Ex:" + e);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a = 0;
|
||||||
|
a = a | 100;
|
||||||
|
a = a | 1;
|
||||||
|
a = a | 10;
|
||||||
|
System.out.println(a);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
package cz.kamma.mining.helper;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import cz.kamma.mining.Constants;
|
|
||||||
|
|
||||||
public class HttpHelper {
|
|
||||||
|
|
||||||
public static String getStringResponse(String urlStr) {
|
|
||||||
return getStringResponse(urlStr, Constants.DEFAULT_HTTP_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getStringResponse(String urlStr, int timeout) {
|
|
||||||
String output = "";
|
|
||||||
|
|
||||||
try {
|
|
||||||
URL url = new URL(urlStr);
|
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
||||||
conn.setDoInput(true);
|
|
||||||
conn.setDoOutput(false);
|
|
||||||
conn.setConnectTimeout(timeout);
|
|
||||||
conn.setRequestProperty("User-Agent",
|
|
||||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36");
|
|
||||||
conn.connect();
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
||||||
String inputLine;
|
|
||||||
while ((inputLine = in.readLine()) != null)
|
|
||||||
output += inputLine;
|
|
||||||
in.close();
|
|
||||||
conn.disconnect();
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("Error while getting HTTP response from " + urlStr + ". Ex:" + e);
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user