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.

OSBuddy Exchange Price Lookup (Java 8)

Featured Replies

Simple and native:

		int twistedBowId = 20997;
		String webAddress = null;
		String webContents = null;
		Map<String, String> jsonData = null;
		
		try {
			
			webAddress = "https://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + twistedBowId;
			
			webContents = downloadWebpage(webAddress);
			
			jsonData = parseJsonKeyValuePairs(webContents);
			
			logger.debug(jsonData);
			
		} catch (IOException e) {
			logger.error("Failed to load price for: " + twistedBowId, e);
		}

Which outputs:

Quote

{buyingQuantity=3, buying=1090772410, overall=1090859846, selling=1090991000, sellingQuantity=2}

All that's missing is the parsing and possibly even a wrapper class. But the content's there.

The other functions (downloadWebpage & parseJsonKey:

	/**
	 * Download all contents from a URL
	 * 
	 * @param address
	 *            - Web site address
	 * @return Contents
	 * @throws IOException
	 *             Error input/output
	 */
	public static String downloadWebpage(String address) throws IOException {
		
		String result = "";
		String nextLine = null;
		
		try (
				InputStream inputStream = new URL(address).openStream();
				InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
				BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
			) {
			
			while ((nextLine = bufferedReader.readLine()) != null) {
				
				result += nextLine;
			}
		}
		
		return result;
	}
	
	/**
	 * Simple JSON parser to extract key & value pairs.
	 * 
	 * Note: values must be numbers.
	 * 
	 * @param input
	 *            - JSON input
	 * @return Mapped contents
	 */
	public static Map<String, String> parseJsonKeyValuePairs(String input) {
		
		final Map<String, String> result = new HashMap<>();
		final Pattern pattern = Pattern.compile(".*?\"(.*?)\":(\\d+)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);		
		final Matcher matcher = pattern.matcher(input);
		
		while (matcher.find()) {
			
			result.put(matcher.group(1), matcher.group(2));
		}
		
		return result;
	}

I wrote my own JSON parser, but it's very simple and will only work where the values are numeric. I'm staying away from any libraries that aren't packaged with Java.

Also, don't suppress errors. If the errors are thrown at a point in the code where it can't be logged out, just keep throwing it on up the stack until it reaches a point where it can. Errors are useful; if you suppress them, then you're going to have a bad time.

Edited by liverare

  • 1 month later...

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.