- Joined
- Oct 30, 2014
- Messages
- 3,453
- Thread Author
- #1
Pretty much stolen, updated, and improved from TopBot, credits to whoever made that.
Enjoy lads.
Code:
package productions.celestial.api.osrs;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class PriceLookup {
private static InputStream is;
private static InputStreamReader isr;
private static BufferedReader br;
private static String[] getData(int id) {
try {
final URL url = new URL(
"https://api.rsbuddy.com/grandExchange?a=guidePrice&i="
+ id);
final URLConnection con = url.openConnection();
is = con.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
final String line = br.readLine();
if (line != null) {
return line.split(",");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
} else if (isr != null) {
isr.close();
} else if (is != null) {
is.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public static int getAveragePrice(final int id) {
final String[] data = getData(id);
if (data != null && data.length == 5) {
return Integer.parseInt(data[0].replaceAll("\\D", ""));
}
return -1;
}
public static int getAverageBuyingOffer(final int id) {
final String[] data = getData(id);
if (data != null && data.length == 5) {
return Integer.parseInt(data[1].replaceAll("\\D", ""));
}
return -1;
}
public static int getAverageBuyingQuantity(final int id) {
final String[] data = getData(id);
if (data != null && data.length == 5) {
return Integer.parseInt(data[2].replaceAll("\\D", ""));
}
return -1;
}
public static int getAverageSellingOffer(final int id) {
final String[] data = getData(id);
if (data != null && data.length == 5) {
return Integer.parseInt(data[3].replaceAll("\\D", ""));
}
return -1;
}
public static int getAverageSellingQuantity(final int id) {
final String[] data = getData(id);
if (data != null && data.length == 5) {
return Integer.parseInt(data[4].replaceAll("\\D", ""));
}
return -1;
}
}
Enjoy lads.