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.

How to get the price of an item in the GE?

Featured Replies

I have the link "GE" where I get, by Json, the price per ID, of each item, how can I get only the price that said Json contains?

Instead of using rs GE, use rsbuddy GE as its more reflective of actual prices imo...

Following code was found elsewhere and adopted for my usecase (sorry cant remember source)

private final static String RSBUDDY_URL = "https://rsbuddy.com/exchange/summary.json";

 

 

    public static HashMap<String, Integer> getPriceMap(List<String> items) {
		HashMap<String, Integer> priceMap = new HashMap<>();

		try {
			URL url = new URL(RSBUDDY_URL);
			BufferedReader jsonFile = new BufferedReader(new InputStreamReader(url.openStream()));
			JsonObject priceJSON = JsonObject.readFrom(jsonFile.readLine());
			Iterator<Member> iterator = priceJSON.iterator();
			
			while (iterator.hasNext()) {
				JsonObject itemJSON = priceJSON.get(iterator.next().getName()).asObject();
				String itemName = itemJSON.get("name").asString();
				if (items.contains(itemName)) {
					priceMap.put(itemName, itemJSON.get("buy_average").asInt());
				}
			}
		} catch (Exception e) {
		}
		return priceMap;
	}

Then, every time you loot an item or if you already know the item name, add it to a list of strings. You can use it as such....

HashMap<String,Integer> itemPrices = new HashMap();

itemPrices = getPriceMap(items);

For keeping a list of total looted you could (inefficiently, sorry unwilling to share my code)

        for(String item : items){
            itemPrices = getPriceMap(items);
            try {
            total = total + itemPrices.get(item);
            }
            catch (Exception e) {
                log("Empty");
            }
            
        }
        items.clear();
}

 

You can use the following library (literally just copy and paste the .java files into your code, I don't know of a better way of doing this)

https://github.com/ralfstx/minimal-json

Edited by Beenrange

  • Author

I needed something simpler, something to just indicate the ID, thanks for the code fragment and for the advice.

Price.java

package scripts;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Iterator;
import java.util.List;

import json.JsonObject;
import json.JsonObject.Member;

public class Price {

	private final static String RSBUDDY_URL = "https://rsbuddy.com/exchange/summary.json";

	public int getPrice(List<Integer> items) {
		int price = 0;

		try {
			URL url = new URL(RSBUDDY_URL);
			BufferedReader jsonFile = new BufferedReader(new InputStreamReader(url.openStream()));
			
			JsonObject priceJSON = JsonObject.readFrom(jsonFile.readLine());
			Iterator<Member> iterator = priceJSON.iterator();
			
			while (iterator.hasNext()) {
				JsonObject itemJSON = priceJSON.get(iterator.next().getName()).asObject();
				int itemID = itemJSON.get("id").asInt();
				if (items.contains(itemID)) {
					price = itemJSON.get("buy_average").asInt();
					break;
				}
			}
		} catch (Exception e) {
		}
		return price;
	}
}

Usage:

final Price price = new Price();
ArrayList<Integer> items = new ArrayList<Integer>(); 
items.add(434);
price.getPrice(items);

 

Edited by trainux

  • Author
23 hours ago, Beenrange said:

Instead of using rs GE, use rsbuddy GE as its more reflective of actual prices imo...

Following code was found elsewhere and adopted for my usecase (sorry cant remember source)


private final static String RSBUDDY_URL = "https://rsbuddy.com/exchange/summary.json";

 

 


    public static HashMap<String, Integer> getPriceMap(List<String> items) {
		HashMap<String, Integer> priceMap = new HashMap<>();

		try {
			URL url = new URL(RSBUDDY_URL);
			BufferedReader jsonFile = new BufferedReader(new InputStreamReader(url.openStream()));
			JsonObject priceJSON = JsonObject.readFrom(jsonFile.readLine());
			Iterator<Member> iterator = priceJSON.iterator();
			
			while (iterator.hasNext()) {
				JsonObject itemJSON = priceJSON.get(iterator.next().getName()).asObject();
				String itemName = itemJSON.get("name").asString();
				if (items.contains(itemName)) {
					priceMap.put(itemName, itemJSON.get("buy_average").asInt());
				}
			}
		} catch (Exception e) {
		}
		return priceMap;
	}

Then, every time you loot an item or if you already know the item name, add it to a list of strings. You can use it as such....


HashMap<String,Integer> itemPrices = new HashMap();

itemPrices = getPriceMap(items);

For keeping a list of total looted you could (inefficiently, sorry unwilling to share my code)


        for(String item : items){
            itemPrices = getPriceMap(items);
            try {
            total = total + itemPrices.get(item);
            }
            catch (Exception e) {
                log("Empty");
            }
            
        }
        items.clear();
}

 

You can use the following library (literally just copy and paste the .java files into your code, I don't know of a better way of doing this)

https://github.com/ralfstx/minimal-json

thank you very much brother.
 

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.