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

Strange error

Featured Replies

Several of my scripts started erroring out and it happens when I use code like this:

Spoiler

PriceLookup prices = new PriceLookup();
        String bucketPrice = prices
                .getPriceByName("Bucket");
        int bucketPriceInt = (Integer.parseInt(bucketPrice));
        int bucketBuyPrice = (int) (bucketPriceInt * 1.25);
        int numBuckets = (int) script.bank.getAmount("Bucket");
        int bucketsNeeded = (14 - numBuckets);

I use this to determine how much of something to buy obviously. This has worked solidly for months up until yesterday, this morning the bots are standing still and throwing this error:

 

Spoiler

[ERROR][Bot #1][10/25 09:40:42 AM]: Error in script executor!
java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at BuyBuckets.execute(BuyBuckets.java:43)
    at JubSapphireRings.onLoop(JubSapphireRings.java:48)
    at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(ro:134)
    at java.lang.Thread.run(Unknown Source)

I didn't change anything with the scripts, and the bot didn't change, anyone have any idea what would cause this?

we need code for your pricelookup and it seems that it isnt getting a number back, just an empty string and Integer.parseInt(...) cant parse an empty string.

  • Author

PriceLookup.java:


 

Spoiler

 

/**
 * @author Jacob Smallridge - Polycoding/Polymorphism
 * Polycoding 2017 http://polycoding.com/
 * 
 * Please leave comments & documentation in place. Modify and distribute as you please.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.URL;

public class PriceLookup {

    private static final String PRICES_BASE = "http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=";

    private static final String ITEMS_BASE = "http://polycoding.com/osb/itemIdNames.php?getId=";

    private static final String[][] VALUE_MATRIX = { { "K", "1000" }, { "M", "1000000" },
            { "B", "1000000000" }, { "T", "1000000000000" } };

    public PriceLookup() {

    }

    /**
     * Retrieves an item's price from Jagex using it's name.
     * 
     * @param name
     * @return String representation of price OR empty String on failure
     */
    public String getPriceByName(String name) {
        try {
            final String id = getId(name.replace(" ", "%20"));
            if (id == null || id.trim().isEmpty())
                return "";
            return parseRS(Integer.valueOf(id));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
    }

    /**
     * Retrieves an item's price from Jagex using it's in-game ID
     * 
     * @param id
     * @return String representation of price OR empty String on failure
     */
    public String getPriceById(int id) {
        try {
            final String price = parseRS(id);
            if (price == null || price.trim().isEmpty())
                return "";
            return price;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
    }

    /**
     * Parses the JSON from RuneScape website
     * 
     * @param itemID
     * @return itemPrice
     * @throws IOException
     */
    private String parseRS(final int itemID) throws IOException {
        final URL url = new URL(PRICES_BASE + itemID);
        BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        String price = null;
        while ((line = file.readLine()) != null) {
            if (line.contains("price")) {
                price = (line).trim();
            }
        }
        price = price.substring(price.indexOf("current"), price.indexOf("today")).replace("\"", "");
        price = price.substring(price.indexOf("price:") + 6, price.lastIndexOf("}"));
        price = addZeros(price.toUpperCase());
        file.close();
        return price.replace(",", "");
    }

    /**
     * Queries Polycoding server to exchange an item's name for it's ID
     * 
     * @param itemName
     *            Items name
     * @return Empty string on failure or the raw ID as a String
     * @throws IOException
     */
    public String getId(String itemName) throws IOException {
        final URL url = new URL(ITEMS_BASE + itemName);
        BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        String content = null;
        while ((line = file.readLine()) != null) {
            content = line.trim();
        }
        file.close();
        return content;
    }

    /**
     * Should convert jagex's 15k to 15000 and 15m to 15000000, etc etc
     * 
     * @param str
     * @return Unformatted String representation of any number input
     */
    private String addZeros(String str) {
        for (int i = 0; i < VALUE_MATRIX.length; i++) {
            if (str.endsWith(VALUE_MATRIX[0])) {
                BigDecimal temp = new BigDecimal(str.substring(0, str.indexOf(VALUE_MATRIX[0])));
                temp = temp.multiply(new BigDecimal(VALUE_MATRIX[1]));
                str = temp.toBigInteger().toString();
                break;
            }
        }
        return str;

    }
}

 

 

Yeah, I wonder why :think:

Ofc you are depending on polycoding.com to get item id's then get prices from rs site, but the site is down so you should use a diff method to get the prices.

Edited by Vilius

7 minutes ago, sudoinit6 said:

PriceLookup.java:


 

  Hide contents

 

/**
 * @author Jacob Smallridge - Polycoding/Polymorphism
 * Polycoding 2017 http://polycoding.com/
 * 
 * Please leave comments & documentation in place. Modify and distribute as you please.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.URL;

public class PriceLookup {

    private static final String PRICES_BASE = "http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=";

    private static final String ITEMS_BASE = "http://polycoding.com/osb/itemIdNames.php?getId=";

    private static final String[][] VALUE_MATRIX = { { "K", "1000" }, { "M", "1000000" },
            { "B", "1000000000" }, { "T", "1000000000000" } };

    public PriceLookup() {

    }

    /**
     * Retrieves an item's price from Jagex using it's name.
     * 
     * @param name
     * @return String representation of price OR empty String on failure
     */
    public String getPriceByName(String name) {
        try {
            final String id = getId(name.replace(" ", "%20"));
            if (id == null || id.trim().isEmpty())
                return "";
            return parseRS(Integer.valueOf(id));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
    }

    /**
     * Retrieves an item's price from Jagex using it's in-game ID
     * 
     * @param id
     * @return String representation of price OR empty String on failure
     */
    public String getPriceById(int id) {
        try {
            final String price = parseRS(id);
            if (price == null || price.trim().isEmpty())
                return "";
            return price;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
    }

    /**
     * Parses the JSON from RuneScape website
     * 
     * @param itemID
     * @return itemPrice
     * @throws IOException
     */
    private String parseRS(final int itemID) throws IOException {
        final URL url = new URL(PRICES_BASE + itemID);
        BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        String price = null;
        while ((line = file.readLine()) != null) {
            if (line.contains("price")) {
                price = (line).trim();
            }
        }
        price = price.substring(price.indexOf("current"), price.indexOf("today")).replace("\"", "");
        price = price.substring(price.indexOf("price:") + 6, price.lastIndexOf("}"));
        price = addZeros(price.toUpperCase());
        file.close();
        return price.replace(",", "");
    }

    /**
     * Queries Polycoding server to exchange an item's name for it's ID
     * 
     * @param itemName
     *            Items name
     * @return Empty string on failure or the raw ID as a String
     * @throws IOException
     */
    public String getId(String itemName) throws IOException {
        final URL url = new URL(ITEMS_BASE + itemName);
        BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        String content = null;
        while ((line = file.readLine()) != null) {
            content = line.trim();
        }
        file.close();
        return content;
    }

    /**
     * Should convert jagex's 15k to 15000 and 15m to 15000000, etc etc
     * 
     * @param str
     * @return Unformatted String representation of any number input
     */
    private String addZeros(String str) {
        for (int i = 0; i < VALUE_MATRIX.length; i++) {
            if (str.endsWith(VALUE_MATRIX[0])) {
                BigDecimal temp = new BigDecimal(str.substring(0, str.indexOf(VALUE_MATRIX[0])));
                temp = temp.multiply(new BigDecimal(VALUE_MATRIX[1]));
                str = temp.toBigInteger().toString();
                break;
            }
        }
        return str;

    }
}

 

 

have you checked if the rs website has changed?

  • Author

Thanks all, price checker was broken, implemented Explv's in its place, all is goo.

 

Explv deserves a raise!

 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

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.