1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
// 0 1 2 3 4 5EX 6 7 8 9 10 11 12 13 14 15 16Wis 17Por 18Armo 19Whet 20Baub 21 22 23Mirr 24Eter 25Pera 26Dusk 27Midn 28Dawn 29Noon 30Grief 31Rage 32Hope 33Igno 34 35Eber 36Yrie 37Inya 38Volk Offer
String currency[] = {"Alte", "Fuse", "Alch", "Chao", "Gcp ", null, "Chro", "Jewl", "Chan", "Chis", "Scou", "Bles", "Regr", "Rega", "Divi", "Vaal", null, null, null, null, null, "Tran", "Augm", null, null, null, null, null, null, null, null, null, null, null , "Silv", null, null, null, null, null };
double ratios[][] = new double[currency.length][currency.length];
for ( int i = 0; i < currency.length; i++){
for (int j=0; j < currency.length; j++){
if (currency[j] != null && currency[i] != null) { //unwichtige sollen direkt rausgefiltert werden
String url = "http://currency.poe.trade/search?league=Prophecy&online=x&want="+(i+1)+"&have="+(j+1);
try {
HashMap<String, String> result = read(url);
if (result != null) {
if (result.get("data-sellvalue") != null || result.get("data-sellvalue")!= null ) {
//System.out.println(currency [j]+" to "+ currency[i]); zum testen ob es richtig ausgelesen wird
//System.out.println(result.get("data-sellvalue") + "\t" + result.get("data-buyvalue"));
ratios [i][j]= Double.parseDouble(result.get("data-sellvalue")) / Double.parseDouble(result.get("data-buyvalue")) ;
System.out.println(ratios [i][j]);
} // end of if
}
}catch (IOException e) {
e.printStackTrace();
}
}
}
}
printMatrix(ratios, currency);
} //end of main
public static HashMap<String, String> read(String url) throws IOException {
String[] parts = url.split("[=&]");
if (parts.length < 4)
return null;
HashMap<String, String> result = new HashMap<String, String>();
result.put(parts[parts.length - 4], parts[parts.length - 3]);
result.put(parts[parts.length - 2], parts[parts.length - 1]);
String website = getUrlSource(url);
website = website.substring(website.indexOf("<div class=\"displayoffer\"") + "<div class=\"displayoffer\"".length());
website = website.substring(0, website.indexOf(">"));
website = website.trim();
website = website.replace("\"", "");
parts = website.split("[= ]");
for (int i = 0; i < parts.length - 1; i += 2)
result.put(parts[i], parts[i + 1]);
return result;
}
private static String getUrlSource(String urlString) throws IOException
{
StringBuilder result = new StringBuilder();
URL url = new URL(urlString);
URLConnection spoof = url.openConnection();
spoof.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)");
BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
String line = "";
while ((line = in.readLine()) != null) {
result.append(line + "\n");
}
in.close();
return result.toString();
}
private static void printMatrix (double[][] rations, String[] currency)
{
System.out.print(" ");
for (int i=0; i < currency.length; i++){
if( currency[i] != null ){
System.out.print("| "+currency[i]);
}
}
System.out.println();
for ( int j = 0; j < currency.length; j++){
if (currency[j]!= null) {
System.out.print(currency[j]+" |");
for (int i=0; i < currency.length; i++){
if (currency[i] != null){
System.out.print( Math.round(100.0 * rations[i][j]) / 100.0+" |");
}
}
System.out.println();
}
}
}
} |