Jump to content

GE Data (get price etc. by item name) no external libraries required


Recommended Posts

  • 4 weeks later...
Posted

How do you change for average buy and average sell

soz double post

 

The data is retrieved in the format:

{"overall":369,"buying":372,"buyingQuantity":108551,"selling":367,"sellingQuantity":121543}

Using a URL such as: http://api.rsbuddy.com/grandExchange?a=guidePrice&i=1515

 

 

The following method retrieves the "overall" value:

private Optional<Integer> getRSBuddyPrice(){
    try {
        URL url = new URL("http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + id);
        URLConnection con = url.openConnection();
        con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
        con.setUseCaches(true);
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String json = br.readLine();
        br.close();
        Matcher matcher = Pattern.compile("\"overall\"\\s*:\\s*(\\d*)").matcher(json);
        return matcher.find() ? Optional.of(Integer.parseInt(matcher.group(1))) : Optional.empty();
    } catch(Exception e){
        e.printStackTrace();
    }
    return Optional.empty();
}

If you wanted to retrieve all of these data items, you can just alter this method to instead return a Map<String, Integer>, and instead of just doing:

Matcher matcher = Pattern.compile("\"overall\"\\s*:\\s*(\\d*)").matcher(json);
return matcher.find() ? Optional.of(Integer.parseInt(matcher.group(1))) : Optional.empty();

Which gets the "overall" value, you can do this for "buying", "selling" etc. and add it to the Map.

 

I will write this up when I get home if you aren't sure how to do it.

  • Like 1
  • 3 weeks later...
  • 2 weeks later...
  • 1 month later...
  • 3 weeks later...
Posted

Any idea why this worked perfectly for me for a couple of first times and started not to find the items I'm looking for? Even tried by replacing the getRSBuddyPrice() method with getOSRScurrentPrice().

 

I noticed there was a slight error in one of the regex patterns, it may have been causing issues for you. I have fixed it in the original post.

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...