Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Pulling GE price's

Featured Replies

I'm trying to use Explv's script to pull GE data but I can't figure out how to actually paint the data on screen.

I've created the two classes "RSExchange" and "ExchangeItem" and then there's this snippet:

Quote

final RSExchange rsExchange = new RSExchange();
rsExchange.getExchangeItem("Spade").ifPresent(System.out::println);

All I want is the sell average from the JSON response but I don't know how to parse/output that info using paint.

 

Edited by bumzag

I wrote up a quick class to get item prices from the runescape's ge services.

 

For some reason I don't have the spoiler button? Anyways here's the class.

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

public final class OsRsExchange {
    private final HashMap<Integer, Long> cachedItems = new HashMap<>();
    private static OsRsExchange instance;

    private OsRsExchange() {}

    public static OsRsExchange getInstance() {
        if (instance == null)
            instance = new OsRsExchange();

        return instance;
    }

    public void cacheItemPricesFromArray(int[] itemIdsArray) {
        for (int value : itemIdsArray) {
            cacheItemPrice(value);
        }
    }

    public boolean cacheItemPrice(int itemId) {
        String urlLink = "http://services.runescape.com/m=itemdb_oldschool//viewitem?obj=" + itemId;
        try {
            URL url = new URL(urlLink);
            URLConnection connection = url.openConnection();
            InputStream inputStream = connection.getInputStream();

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

            String line;
            StringBuilder sb = new StringBuilder();

            while ((line = bufferedReader.readLine()) != null)
                sb.append(line);

            int indexOfPrice = sb.indexOf("Current Guide Price");

            String priceString = "";

            try {
                priceString = sb.substring(indexOfPrice, sb.indexOf(">", indexOfPrice));
            } catch (StringIndexOutOfBoundsException si) {
                si.printStackTrace();
                System.out.println("Invalid Item Id!");
                return false;
            }

            priceString = priceString.substring(priceString.indexOf("'") + 1, priceString.lastIndexOf("'"));
            String[] splitPriceString = priceString.split(",");

            sb = new StringBuilder();

            for (String s : splitPriceString) {
                sb.append(s);
            }

            long priceOfItem = -1;

            try {
                priceOfItem = Long.parseLong(sb.toString());
            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
                System.out.println("Incorrect string format to be converted to a long!");
            }

            if (cachedItems.containsKey(itemId))
                cachedItems.replace(itemId, priceOfItem);
            else
                cachedItems.put(itemId, priceOfItem);

            return true;

        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

    public long getPriceOfItem(int itemId) {
        if (!cachedItems.containsKey(itemId)) {
            System.out.println("The cached items does not contain this Item Id!");
            return -1;
        }

        return cachedItems.get(itemId);
    }

    public HashMap<Integer, Long> getCachedItems() {
        return cachedItems;
    }

    public void clearCachedItems() {
        cachedItems.clear();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (cachedItems.size() > 0)
            cachedItems.forEach((id, price) -> sb.append(String.format("%s :: %s\n", id, price)));

        return sb.toString();
    }
}

 

To use

//Recommended to use an array in the onStart of your script as retrieving the prices is a pretty taxing process.
int[] itemIds = new int[]{556, 892, 811, 1436, 2627, 5641};
OsRsExchange.getInstance().cacheItemPricesFromArray(itemIds);
System.out.println(OsRsExchange.getInstance());

//If you want to do individual items
OsRsExchange.getInstance().cacheItemPrice(3202);
System.out.println(OsRsExchange.getInstance());

//Retrieve price of item by calling getPriceOfItem()
long price = OsRsExchange.getInstance().getPriceOfItem(2627);
System.out.println(price);
  • 3 weeks later...
On 12/27/2019 at 10:18 AM, BravoTaco said:

I wrote up a quick class to get item prices from the runescape's ge services.

 

For some reason I don't have the spoiler button? Anyways here's the class.


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

public final class OsRsExchange {
    private final HashMap<Integer, Long> cachedItems = new HashMap<>();
    private static OsRsExchange instance;

    private OsRsExchange() {}

    public static OsRsExchange getInstance() {
        if (instance == null)
            instance = new OsRsExchange();

        return instance;
    }

    public void cacheItemPricesFromArray(int[] itemIdsArray) {
        for (int value : itemIdsArray) {
            cacheItemPrice(value);
        }
    }

    public boolean cacheItemPrice(int itemId) {
        String urlLink = "http://services.runescape.com/m=itemdb_oldschool//viewitem?obj=" + itemId;
        try {
            URL url = new URL(urlLink);
            URLConnection connection = url.openConnection();
            InputStream inputStream = connection.getInputStream();

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

            String line;
            StringBuilder sb = new StringBuilder();

            while ((line = bufferedReader.readLine()) != null)
                sb.append(line);

            int indexOfPrice = sb.indexOf("Current Guide Price");

            String priceString = "";

            try {
                priceString = sb.substring(indexOfPrice, sb.indexOf(">", indexOfPrice));
            } catch (StringIndexOutOfBoundsException si) {
                si.printStackTrace();
                System.out.println("Invalid Item Id!");
                return false;
            }

            priceString = priceString.substring(priceString.indexOf("'") + 1, priceString.lastIndexOf("'"));
            String[] splitPriceString = priceString.split(",");

            sb = new StringBuilder();

            for (String s : splitPriceString) {
                sb.append(s);
            }

            long priceOfItem = -1;

            try {
                priceOfItem = Long.parseLong(sb.toString());
            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
                System.out.println("Incorrect string format to be converted to a long!");
            }

            if (cachedItems.containsKey(itemId))
                cachedItems.replace(itemId, priceOfItem);
            else
                cachedItems.put(itemId, priceOfItem);

            return true;

        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

    public long getPriceOfItem(int itemId) {
        if (!cachedItems.containsKey(itemId)) {
            System.out.println("The cached items does not contain this Item Id!");
            return -1;
        }

        return cachedItems.get(itemId);
    }

    public HashMap<Integer, Long> getCachedItems() {
        return cachedItems;
    }

    public void clearCachedItems() {
        cachedItems.clear();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (cachedItems.size() > 0)
            cachedItems.forEach((id, price) -> sb.append(String.format("%s :: %s\n", id, price)));

        return sb.toString();
    }
}

 

To use


//Recommended to use an array in the onStart of your script as retrieving the prices is a pretty taxing process.
int[] itemIds = new int[]{556, 892, 811, 1436, 2627, 5641};
OsRsExchange.getInstance().cacheItemPricesFromArray(itemIds);
System.out.println(OsRsExchange.getInstance());

//If you want to do individual items
OsRsExchange.getInstance().cacheItemPrice(3202);
System.out.println(OsRsExchange.getInstance());

//Retrieve price of item by calling getPriceOfItem()
long price = OsRsExchange.getInstance().getPriceOfItem(2627);
System.out.println(price);

Thanks. nice contribution

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.