Jump to content

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


Explv

Recommended Posts

  • 4 weeks later...

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
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

sigh perhaps you should read up on the Java Garbage Collector then.

 

If you are really concerned about memory usage, then perhaps you should use a profiler to see how much memory, and where the memory is being used.

 

It isn't really a concern though. It's just a Map containing a few objects..

How can i get only price?

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...

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.

Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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