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.

Grand Exchange price lookup

Featured Replies

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

public class Exchange {

	public static HashMap<Integer, Integer> cache = new HashMap<Integer, Integer>();
	
	public static String getData(int itemID) {
		try {
			StringBuilder sb = new StringBuilder("https://api.rsbuddy.com/grandExchange?a=guidePrice&i=");
			sb.append(String.valueOf(itemID));
			InputStream inputStream = new URL(sb.toString()).openStream();
			InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
			BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
			String line;
			while ((line = bufferedReader.readLine()) != null) {
				if (line.contains("{")) {
					sb = new StringBuilder(line);
					//Remove { and }
					sb.deleteCharAt(0);
					//sb.deleteCharAt((line.length() - 1));
					return sb.toString();
				}
			}
		}
		catch (Exception e) {
			return e.getMessage();
		}
		return null;
	}
	
	public static String[] parseData(String data) {
		ArrayList<String> holder = new ArrayList<String>();
		String[] parts = data.split(","); //Now we have strings in format "x":y
		for (String s : parts) {
			s = s.replace("\"", ""); //Remove " - now in format x:y
			holder.add(s.split(":")[1]); //Extract y from format x:y
		}
		String[] ret = new String[holder.size()];
		return holder.toArray(ret);
	}
	
	public static int getPrice(int itemID) {
		if (itemID == 995) return 1;
		
		if (cache.containsKey(itemID)) {
			return cache.get(itemID);
		}
		String[] data = parseData(getData(itemID));
		int price = Integer.valueOf(data[0]);
		cache.put(itemID, price);
		return price;
	}
	
}

EDIT: Coins are ID 995; 1gp=1gp so we return 1 there.

 

Usage:

int price = Exchange.getPrice(item.getId());

Edited by Bobrocket

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

public class Exchange {

	public static HashMap<Integer, Integer> cache = new HashMap<Integer, Integer>();
	
	public static String getData(int itemID) {
		try {
			StringBuilder sb = new StringBuilder("https://api.rsbuddy.com/grandExchange?a=guidePrice&i=");
			sb.append(String.valueOf(itemID));
			InputStream inputStream = new URL(sb.toString()).openStream();
			InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
			BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
			String line;
			while ((line = bufferedReader.readLine()) != null) {
				if (line.contains("{")) {
					sb = new StringBuilder(line);
					//Remove { and }
					sb.deleteCharAt(0);
					//sb.deleteCharAt((line.length() - 1));
					return sb.toString();
				}
			}
		}
		catch (Exception e) {
			return e.getMessage();
		}
		return null;
	}
	
	public static String[] parseData(String data) {
		ArrayList<String> holder = new ArrayList<String>();
		String[] parts = data.split(","); //Now we have strings in format "x":y
		for (String s : parts) {
			s = s.replace("\"", ""); //Remove " - now in format x:y
			holder.add(s.split(":")[1]); //Extract y from format x:y
		}
		String[] ret = new String[holder.size()];
		return holder.toArray(ret);
	}
	
	public static int getPrice(int itemID) {
		if (itemID == 995) return 1;
		
		if (cache.containsKey(itemID)) {
			return cache.get(itemID);
		}
		String[] data = parseData(getData(itemID));
		int price = Integer.valueOf(data[0]);
		cache.put(itemID, price);
		return price;
	}
	
}

EDIT: Coins are ID 995; 1gp=1gp so we return 1 there.

 

Usage:

int price = Exchange.getPrice(item.getId());

 

Why don't I see a single .close() in this snippet?

 

angry.png

To make you cry :^)

 

 

Well I hope you fixed it on your code. Not closing streams is a terrible habit and can result in unexpected behavior, especially since the stream isn't being flushed.

Well I hope you fixed it on your code. Not closing streams is a terrible habit and can result in unexpected behavior, especially since the stream isn't being flushed.

 

Don't worry about me babe <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.