Reid Posted March 30, 2015 Share Posted March 30, 2015 (edited) I'm sure somebody will find this useful. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; /** * GrandExchange Price Class * * @author Reid * */ public class GrandExchange { private static final String BASE = "https://api.rsbuddy.com/grandExchange?a=guidePrice&i="; /** * Default Constructor * */ public GrandExchange() { } /** * Gets the overall price of an item. * * @param itemID * @return itemPrice * @throws IOException */ public int getOverallPrice(final int itemID) throws IOException { return parse(itemID,"overall"); } /** * Gets the buying price of an item. * * @param itemID * @return itemPrice * @throws IOException */ public int getBuyingPrice(final int itemID) throws IOException { return parse(itemID,"buying"); } /** * Gets the selling price of an item. * * @param itemID * @return itemPrice * @throws IOException */ public int getSellingPrice(final int itemID) throws IOException { return parse(itemID,"selling"); } /** * Retrieves the price of an item. * * @param itemID * @return itemPrice * @throws IOException */ private int parse(final int itemID, String choice) throws IOException { final URL url = new URL(BASE + itemID); BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream())); String line; String price = null; while ((line = file.readLine()) != null) { if (line.contains("{")) { price = (line).trim(); } } if (choice.equals("buying")){ price = price.substring(price.indexOf(",") + 10, nthOccurrence(price, ',', 1)).trim(); } else if(choice.equals("selling")) { price = price.substring(nthOccurrence(price, ',', 2) + 11 , price.indexOf("sellingQuantity") - 2).trim(); } else { price = price.substring(price.indexOf(":") + 1, price.indexOf(",")).trim(); } file.close(); return Integer.parseInt(price); } private int nthOccurrence(String str, char c, int n) { int pos = str.indexOf(c, 0); while (n-- > 0 && pos != -1) pos = str.indexOf(c, pos + 1); return pos; } } Edited April 3, 2015 by Reid 4 Quote Link to comment Share on other sites More sharing options...
Shakur Posted March 30, 2015 Share Posted March 30, 2015 , usefulness found 1 Quote Link to comment Share on other sites More sharing options...
Czar Posted March 30, 2015 Share Posted March 30, 2015 Good job man! Nice to see some stuff around here 1 Quote Link to comment Share on other sites More sharing options...
Joseph Posted April 18, 2015 Share Posted April 18, 2015 I suggest using a map if you feel like using caching 1 Quote Link to comment Share on other sites More sharing options...
Jack Shep Posted October 25, 2018 Share Posted October 25, 2018 What code would you use to implement this into your script? I'm pretty confused rn. Quote Link to comment Share on other sites More sharing options...
Medusa Posted November 5, 2018 Share Posted November 5, 2018 (edited) On 10/26/2018 at 12:48 AM, Jack Shep said: What code would you use to implement this into your script? I'm pretty confused rn. I'm guessing you'd just want to make a class with this code. Then call the function inside that class, which is called "parse". Then type item id and if you're buying or selling. Example: int onePrice = GrandExchange.parse(1, "buying"); That would get the price of the item with id 1. EDIT: In general you really just want to use the functions provided in the class. Edited November 5, 2018 by Medusaa Quote Link to comment Share on other sites More sharing options...