Rabrg 83 Share Posted June 1, 2016 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 More sharing options...
Nebraska 136 Share Posted June 1, 2016 Was looking for this, thank you! Link to comment Share on other sites More sharing options...
ExoMemphiz 0 Share Posted June 4, 2016 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 More sharing options...
Rabrg 83 Author Share Posted June 4, 2016 I was not getting the correct values which items were giving u incorrect prices Link to comment Share on other sites More sharing options...
veeniqqa 2 Share Posted June 9, 2016 This doesn't work for certain items, some items on my script find it others don't Link to comment Share on other sites More sharing options...
slasso 27 Share Posted June 9, 2016 This doesn't work for certain items, some items on my script find it others don't Which items don't work? Link to comment Share on other sites More sharing options...
Dennis 2 Share Posted June 9, 2016 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 More sharing options...
Rabrg 83 Author Share Posted June 9, 2016 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 More sharing options...
Dennis 2 Share Posted June 9, 2016 fixed & updated It no longer has the base url Link to comment Share on other sites More sharing options...
Rabrg 83 Author Share Posted June 9, 2016 It no longer has the base url fixed & updated Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.