Jump to content

Getting high alch prices


Recommended Posts

Posted
On 5/14/2018 at 7:06 AM, anderiel said:

i kind of hoped for a simpler solution than scraping sites.

The simplest solution is just creating an enum and hardcoding the alch values.

 

22 hours ago, Plaxonn said:

Very easy dude!

Alchmate is the way.

I hope I'm not breaking the rules by saying that, no advertisment intended.

He asked for a solution that didn't involve scraping sites

Posted
18 hours ago, ThatGamerBlue said:

Not sure if OSBot has a getPrice() type function for items (couldn't see it in the API) which would return the item's price in a general store (example from another client), but if it does you can multiply that value by 0.6 for high alch, 0.4 for low alch.

Nice! This i did not know. Not sure if osbot has such a function, but rsbuddy has api that gives you store prices that i can multiply. I can work with that, thanks.

Posted
10 hours ago, anderiel said:

Nice! This i did not know. Not sure if osbot has such a function, but rsbuddy has api that gives you store prices that i can multiply. I can work with that, thanks.

Yes, you can use https://rsbuddy.com/exchange/summary.json

Example (using https://github.com/fangyidong/json-simple)

 

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public final class AlchValues {

    private static final float STORE_PRICE_TO_HIGH_ALCH_MULTIPLIER = 0.6f;
    private static final float STORE_PRICE_TO_LOW_ALCH_MULTIPLIER = 0.4f;

    private final JSONObject ITEMS_JSON;

    public AlchValues() throws IOException, ParseException {
        ITEMS_JSON = getItemsJSON();
    }

    public static void main(String[] args) {
        AlchValues alchValues = null;
        try {
            alchValues = new AlchValues();
        } catch (IOException | ParseException e) {
            System.err.println("Failed to fetch alch values");
            System.exit(1);
        }

        System.out.println("Yew logs store price: " + alchValues.getStorePrice(1515));
        System.out.println("Yew logs high alch: " + alchValues.getHighAlchValue(1515));
        System.out.println("Yew logs low alch: " + alchValues.getLowAlchValue(1515));
    }

    private JSONObject getItemsJSON() throws IOException, ParseException {
        URL url = new URL("https://rsbuddy.com/exchange/summary.json");
        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);

        JSONObject itemsJSON;

        try (InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream());
             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
            JSONParser jsonParser = new JSONParser();
            itemsJSON = (JSONObject) jsonParser.parse(bufferedReader);
        }

        return itemsJSON;
    }

    public int getHighAlchValue(final int itemID) {
        return (int) (getStorePrice(itemID) * STORE_PRICE_TO_HIGH_ALCH_MULTIPLIER);
    }

    public int getLowAlchValue(final int itemID) {
        return (int) (getStorePrice(itemID) * STORE_PRICE_TO_LOW_ALCH_MULTIPLIER);
    }

    public int getStorePrice(final int itemID) {
        return Math.toIntExact((long) getItemJSON(itemID).get("sp"));
    }

    private JSONObject getItemJSON(final int itemID) {
        return (JSONObject) ITEMS_JSON.get(String.valueOf(itemID));
    }
}


Output:
 

Yew logs store price: 160
Yew logs high alch: 96
Yew logs low alch: 64


 

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