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.

GE Data

Featured Replies

Seems like other snippets of getting item data didn't work so I just made one myself. Who knows how long this might last.

If you're interested in storing values you wish to lookup instead of having to parse the json data stored, please implement it yourself (hashmap). I left it out on purpose.

How it works:

Spoiler

1. Splits each JSON item into a 'block' (array of strings)

2. Gets each property from the block (property:value)

3. returns the value if it matches the property + name of item

Usage:

Spoiler

All look-ups return an Optional<String>. Be sure to convert to numeric if that's what you're after.


ItemLookup.get("Trout", Property.SELL_AVERAGE); // case sensitive

 

Code:

Spoiler

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
import java.util.Optional;
import java.util.regex.Pattern;

public class ItemLookup {

    private static String json;

    private ItemLookup(){ }

    private static void initData(){
        try {
            URL url = new URL("https://rsbuddy.com/exchange/summary.json");
            URLConnection connect = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream()));
            json = in.readLine();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Optional<String> get(String itemName, Property property){

        if(json == null)
        {
            initData();
        }

        Optional<String> itemBlock =  Arrays
                .stream(json.split("\\{"))
                .filter(phrase -> findString(itemName, phrase))
                .findFirst();

        if(itemBlock.isPresent())
        {
            return Arrays
                    .stream(itemBlock.get().split(","))
                    .filter(phrase -> findString(property.getProperty(), phrase))
                    .map(ItemLookup::clean)
                    .findFirst();
        }
        else
        {
            return Optional.empty();
        }
    }

    private static boolean findString(String target, String phrase){
        return phrase.matches(".*\"" + Pattern.quote(target) + "\".*");
    }

    private static String clean(String value){
        value = value.split(":")[1];
        return value.replaceAll("}","").replaceAll("\"","");
    }
}

 

Spoiler

public enum Property {

    ID("id"),
    NAME("name"),
    MEMBERS("members"),
    SP("sp"),
    BUY_AVERAGE("buy_average"),
    BUY_QUANTITY("buy_quantity"),
    SELL_AVERAGE("sell_average"),
    SELL_QUANTITY("sell_quantity"),
    OVERALL_AVERAGE("overall_average"),
    OVERALL_QUANTITY("overall_quantity");

    private String property;

    Property(String property){
        this.property = property;
    }

    public String getProperty() {
        return property;
    }
}

 

 

Edited by dreameo

  • 5 months later...

Just because I know people will have issues converting this. This is how you do that.

 String Itemname = "Logs";
        Optional<String> Itemprice = ItemLookup.get(Itemname, Property.SELL_AVERAGE);
        int ItemPriceConverted = Integer.valueOf(Itemprice.get());
        log(Itemname + " are worth " + ItemPriceConverted + " gp");

Great stuff dreameo <3

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.