Jump to content

Get item price directly through GE?


Recommended Posts

Posted
1 minute ago, Viston said:

Like the price of Price Per Item: ?

Isn't there a widget for it? If there is a widget, grab the filter, and filter out all unnecessary stuff out, so you only have the integer.

Or do you mean this?

 

Ye price per item, is there some snippet without json though?

I remember explv saying so but i can't find the thread

Posted (edited)

Not mine:
 

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;

public class Exchange {

    private static HashMap<Integer, Integer> cache = new HashMap<Integer, Integer>();

    public static String getData(int itemID) {
        try {
            StringBuilder sb = new StringBuilder("https://api.rsbuddy.com/grandExchange?a=guidePrice&i=");
            sb.append(String.valueOf(itemID));
            InputStream inputStream = new URL(sb.toString()).openStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                if (line.contains("{")) {
                    sb = new StringBuilder(line);
                    sb.deleteCharAt(0);
                    return sb.toString();
                }
            }
        }
        catch (Exception e) {
            return e.getMessage();
        }
        return null;
    }

    public static String[] parseData(String data) {
        ArrayList<String> holder = new ArrayList<String>();
        String[] parts = data.split(","); //Now we have strings in format "x":y
        for (String s : parts) {
            s = s.replace("\"", ""); //Remove " - now in format x:y
            holder.add(s.split(":")[1]); //Extract y from format x:y
        }
        String[] ret = new String[holder.size()];
        return holder.toArray(ret);
    }

    public static int getPrice(int itemID) {
        if (itemID == 995) return 1;

        if (cache.containsKey(itemID)) {
            return cache.get(itemID);
        }
        String[] data = parseData(getData(itemID));
        int price = Integer.valueOf(data[0]);
        cache.put(itemID, price);
        return price;
    }

}

 

Use:
 

Item item = getInventory().getItem("Coal");
int price = Exchange.getPrice(item.getId())

 

Edited by HunterRS
  • Like 2
  • Heart 1
Posted (edited)
5 hours ago, atoo said:

Ye price per item, is there some snippet without json though?

I remember explv saying so but i can't find the thread

That thread he linked is without the requirement of any external libraries. It even says so in the title.

I would recommend using it because it allows you to lookup items using their name rather than id.

I have another topic in the snippets section which does use a JSON library. Not sure why you wouldn't use it, JSON simple for example is open source and only a few classes, so you can just copy it into your project.

As for getting the price in game, isn't it just a widget? If not there may be a config?

Edited by Explv
  • Like 1
Posted (edited)
40 minutes ago, Explv said:

That thread he linked is without the requirement of any external libraries. It even says so in the title.

I would recommend using it because it allows you to lookup items using their name rather than id.

I have another topic in the snippets section which does use a JSON library. Not sure why you wouldn't use it, JSON simple for example is open source and only a few classes, so you can just copy it into your project.

As for getting the price in game, isn't it just a widget? If not there may be a config?

Ye ill look into it when i work more on my fletcher, thanks.

I'll also look into using the widget but i think using your snippet would be a lot better imo

 

I got it working, thanks everyone for the help!

Edited by atoo

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...