Vlad 216 Posted March 28, 2015 RSBuddy/OSBuddy Exchange has more accurate prices than Zybez for the most part. 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 URLConnection con; private static InputStream is; private static InputStreamReader isr; private static BufferedReader br; private static String[] getData(int itemID) { try { URL url = new URL( "https://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + itemID); con = url.openConnection(); is = con.getInputStream(); isr = new InputStreamReader(is); br = new BufferedReader(isr); 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 getPrice(int itemID) { String[] data = getData(itemID); if (data != null && data.length == 5) { return Integer.parseInt(data[0].replaceAll("\\D", "")); } return 0; } public static int getAverageBuyOffer(int itemID) { String[] data = getData(itemID); if (data != null && data.length == 5) { return Integer.parseInt(data[1].replaceAll("\\D", "")); } return 0; } public static int getAverageSellOffer(int itemID) { String[] data = getData(itemID); if (data != null && data.length == 5) { return Integer.parseInt(data[3].replaceAll("\\D", "")); } return 0; } } Dump of all the prices from March 27, 2015: http://pastebin.com/rQ5dk7mp
Vlad 216 Author Posted April 19, 2015 Updated. OSBuddy updated their API and it broke, but it will now work again.
Explicit 213 Posted April 19, 2015 You should create an enum for each values index in the data row (item price is 0, average buy offer is 1, etc.) and then just have a generic method to grab the value from the row: public static int getValue(DataRowValueIndexOrWhateverYourEnumIsCalled value) { String[] data = getData(itemID); if (data != null && data.length == 5) { return Integer.parseInt(data[value.getIndexOrWhateverTheGetterForIndexIs()].replaceAll("\\D", "")); } return 0; } It might be beneficial to also create a private constructor since everything's static and an instance will never need to be created.
Cardozz 46 Posted February 1, 2016 How would I read all the average buy prices in one go for example? I'm just wondering since it could be useful later on
infallible 28 Posted February 3, 2016 Seems to still work, but the bot lags alot Lags the script a lot when implemented
Dreamlicker 750 Posted February 5, 2016 If you're going to use this, don't call it every time you need a price. Store the prices in a map. I use something like this HashMap<String, Integer> priceMap = new HashMap<>(); priceMap.put(item.getName(), PriceLookup.getPrice(item.getID()); //For each item. Do this only once. Then you can access your items prices with priceMap.get(item.getName()); This may not be the best way of doing it, so if someone else has a better way please share. However, this will give you an access time of O(1) so it's pretty quick. May be able to use a smaller data structure so if you have a better way, show us
Recommended Posts
Archived
This topic is now archived and is closed to further replies.