FearMe Posted February 2, 2014 Share Posted February 2, 2014 (edited) Have fun. /** * @author FearMe * @param name the exact item name * @return the price(not 100% accurate) * @throws IOException */ private int getPrice(String name) throws IOException { if (name.length() <= 3) return 0; URL url = new URL("http://forums.zybez.net/runescape-2007-prices/api/item/" + name.replace("+", "%2B").replace(' ', '+').replace("'", "%27")); URLConnection con = url.openConnection(); con.addRequestProperty("User-Agent", "Mozilla/5.0"); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String line = ""; String inputLine; while ((inputLine = in.readLine()) != null) line += inputLine; in.close(); if (!line.contains("average\":\"")) return 0; line = line.substring(line.indexOf("average\":\"") + "average\":\"".length()); line = line.substring(0, line.indexOf("\"")); return (int) Math.round(Double.parseDouble(line)); } Edited February 3, 2014 by FearMe Link to comment Share on other sites More sharing options...
Toph Posted February 2, 2014 Share Posted February 2, 2014 If you can extend it to check for buy/sell, and only if there's recent offers, and alch prices, that'd make it a lot more usable. That's what I do for my Slayer script Link to comment Share on other sites More sharing options...
FearMe Posted February 2, 2014 Author Share Posted February 2, 2014 If you can extend it to check for buy/sell, and only if there's recent offers, and alch prices, that'd make it a lot more usable. That's what I do for my Slayer script This is more for stuff like calculating money gained per hour, nothing big. If i recall correctly there's a full-fletched library on like the 2nd or 3rd page of this subforum. Link to comment Share on other sites More sharing options...
Toph Posted February 3, 2014 Share Posted February 3, 2014 This is more for stuff like calculating money gained per hour, nothing big. If i recall correctly there's a full-fletched library on like the 2nd or 3rd page of this subforum. There is one but I don't believe it checks for actual offers, and therefor if there's an item with a price of 1,000,000 but that's only people selling, no one buying, it will still return that (incorrect) result. Link to comment Share on other sites More sharing options...
FrostBug Posted February 3, 2014 Share Posted February 3, 2014 Note that certain items with apostrophe or plus signs in their name may require URL encoding replace "+" with %2B and replace " ' " (apostrophe) with %27 Link to comment Share on other sites More sharing options...
FearMe Posted February 3, 2014 Author Share Posted February 3, 2014 Note that certain items with apostrophe or plus signs in their name may require URL encoding replace "+" with %2B and replace " ' " (apostrophe) with %27 Totally forgot that some items have a " ' " in the name, plus sign works fine though. Link to comment Share on other sites More sharing options...
FrostBug Posted February 3, 2014 Share Posted February 3, 2014 (edited) Totally forgot that some items have a " ' " in the name, plus sign works fine though. I can't imagine that plus signs would work fine, since they are interpreted as spaces a Dragon dagger(p+) for example, would be translated to Dragon+dagger(p+) = 3 words: "Dragon", "dagger(p" and ")" Edited February 3, 2014 by FrostBug Link to comment Share on other sites More sharing options...