Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Price lookup


    Rabrg

    Recommended Posts


    private static final String BASE_URL = "http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=";

    private static final int MILLION = 1000000;
    private static final int THOUSAND = 1000;

    int getPrice(final int id) {
    try (final BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(BASE_URL + id).openStream()))) {
    final String raw = reader.readLine().replace(",", "").replace("\"", "").split("price:")[1].split("}")[0];
    return raw.endsWith("m") || raw.endsWith("k") ? (int) (Double.parseDouble(raw.substring(0, raw.length() - 1))
    * (raw.endsWith("m") ? MILLION : THOUSAND)) : Integer.parseInt(raw);
    } catch (final Exception e) {
    e.printStackTrace();
    }
    return -1;
    }
    Link to comment
    Share on other sites

    I was not getting the correct values, so I edited it, and added in billion, if it was needed.

     

    (Hope it's okay, I changed it? If not, tell me and I'll remove it - also, I know your code might be a lot more efficient, but I was getting incorrect values, I havn't tried to optimize mine)

    private static final String BASE_URL = "http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=";
    
    		private static final int BILLION = 1000000000;
    	    private static final int MILLION = 1000000;
    	    private static final int THOUSAND = 1000;
    
    	    static int getPrice(final int id) {
    	        try (final BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(BASE_URL + id).openStream()))) {
    	            String line = reader.readLine();
    	            String sub = line.substring(line.indexOf("\"price\":"));
    	            final String raw = sub.substring("\"price\":".length(), sub.indexOf("}"));
    	            if (raw.endsWith("b")) {
    	            	return (int) Double.parseDouble(raw.substring(0, raw.length() - 1)) * BILLION;
    	            } else if (raw.endsWith("m")) {
    	            	return (int) Double.parseDouble(raw.substring(0, raw.length() - 1)) * MILLION;
    	            } else if (raw.endsWith("k")) {
    	            	return (int) Double.parseDouble(raw.substring(0, raw.length() - 1)) * THOUSAND;
    	            } else {
    	            	return Integer.parseInt(raw);
    	            }
    	        } catch (final Exception e) {
    	            e.printStackTrace();
    	        }
    	        return -1;
    	    }
    
    Link to comment
    Share on other sites

    which items were giving u incorrect prices

     

    Which items don't work?

    Grimy kwuarm, Mithril kiteshield, Grimy lantadyme, Uncut sapphire, Grimy dwarf weed. Looks like all herbs and gems don't work

    Link to comment
    Share on other sites

    Grimy kwuarm, Mithril kiteshield, Grimy lantadyme, Uncut sapphire, Grimy dwarf weed. Looks like all herbs and gems don't work

    fixed & updated

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.