Jump to content
Sign in to follow this  
crezzy

Basic bank evaluator

Recommended Posts

Just wanted to check my bank worth so I wrote a basic script which gets prices from the OSBuddy API.

Place in your local script directory (C/users/YOU/osbot/Scripts)

It will take a few seconds depending on how many items are within your bank.

Note: it will not check the value of untradeable items(e.g blowpipe with scales/darts init)  or coins!

Start the script with your bank open. Output will be shown on client paint.

Download link:

bankeval.jar

Screenshot:

mybot_bank_Eval.png

 

Source code for anyone who wants it:

import java.awt.Graphics2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Crezzy", name = "Bank Evlauator", info = "Determins value of bank", logo = "", version = 1)
public class Main extends Script {

	private int wealth = 0;
	private long startTime;
	private long endTime;

	private static final Pattern pattern = Pattern.compile("(?:\"overall\":)([0-9]+)");

	private static int getPrice(int id) throws MalformedURLException, IOException {
		String url = "http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + id;
		BufferedReader reader = new BufferedReader(
				new InputStreamReader(new URL(String.format(url, id)).openConnection().getInputStream()));
		String line;
		while ((line = reader.readLine()) != null) {
			Matcher m = pattern.matcher(line);
			if (m.find() && m.groupCount() > 0) {
				int overallPrice = Integer.parseInt(m.group(1));
				if (overallPrice == 0) {
					overallPrice = 1;
				}
				return overallPrice;
			}
		}
		return 1;
	}

	@Override
	public void onPaint(Graphics2D g) {
		Graphics2D paint = (Graphics2D) g.create();
		paint.drawString("Amount of time took to get bank wealth: " + formatT(endTime), 10, 310);
		paint.drawString("Amount of items found in bank: " + getBank().getItems().length, 10, 325);
		paint.drawString("Bank amount: " + wealth, 10, 340);
	}

	private String formatT(final long ms) {
		long s = ms / 1000, m = s / 60, h = m / 60;
		s %= 60;
		m %= 60;
		h %= 24;
		return String.format("%02d:%02d:%02d", h, m, s);
	}

	@Override
	public void onStart() {
		startTime = System.currentTimeMillis();
		if (getBank().isOpen()) {
			for (Item i : getBank().getItems()) {
				try {
					wealth = wealth + getPrice(i.getId());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			endTime = System.currentTimeMillis() - startTime;
			log("total wealth = " + wealth);
		}
	}

	@Override
	public int onLoop() throws InterruptedException {
		return 100;
	}

}

 

Edited by crezzy
  • Like 1

Share this post


Link to post
Share on other sites
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.NumberFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "", name = "Bank Evaluator", info = "Determines the value of bank", logo = "", version = 1)
public class Main extends Script {

	private int wealth = 0;
	private long startTime;
	private long endTime;

	private static final Pattern pattern = Pattern.compile("(?:\"overall\":)([0-9]+)");

	private static int getPrice(int id) throws MalformedURLException, IOException {
		String url = "http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + id;
		BufferedReader reader = new BufferedReader(
				new InputStreamReader(new URL(String.format(url, id)).openConnection().getInputStream()));
		String line;
		while ((line = reader.readLine()) != null) {
			Matcher m = pattern.matcher(line);
			if (m.find() && m.groupCount() > 0) {
				int overallPrice = Integer.parseInt(m.group(1));
				if (overallPrice == 0) break;
				return overallPrice;
			}
		}
		reader.close();
		return 0;
	}

	@Override
	public void onPaint(Graphics2D paint) {
		paint.setColor(Color.ORANGE);
		paint.drawString("Amount of time took to get bank wealth: " + formatT(endTime), 10, 310);
		paint.drawString("Amount of items found in bank: " + formatIntegers(getBank().getItems().length), 10, 325);
		paint.drawString("Bank amount: " + formatIntegers(wealth), 10, 340);
	}

	private String formatT(final long ms) {
		long s = ms / 1000, m = s / 60, h = m / 60;
		s %= 60;
		m %= 60;
		h %= 24;
		return String.format("%02d:%02d:%02d", h, m, s);
	}

	@Override
	public void onStart() {
		startTime = System.currentTimeMillis();
		if (getBank().isOpen()) {
			for (Item i : getBank().getItems()) {
				if (i != null){
					try {
						wealth = wealth + (getPrice(i.getId()) * i.getAmount());
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
			endTime = System.currentTimeMillis() - startTime;
		}
	}

	private String formatIntegers(int num) {
		return NumberFormat.getInstance().format(num);
	}

	@Override
	public int onLoop() throws InterruptedException {
		return 1000;
	}

}

made some changes hope u like

Edited by Chris
  • Like 1

Share this post


Link to post
Share on other sites
41 minutes ago, Chris said:

import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.NumberFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "", name = "Bank Evaluator", info = "Determines the value of bank", logo = "", version = 1)
public class Main extends Script {

	private int wealth = 0;
	private long startTime;
	private long endTime;

	private static final Pattern pattern = Pattern.compile("(?:\"overall\":)([0-9]+)");

	private static int getPrice(int id) throws MalformedURLException, IOException {
		String url = "http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + id;
		BufferedReader reader = new BufferedReader(
				new InputStreamReader(new URL(String.format(url, id)).openConnection().getInputStream()));
		String line;
		while ((line = reader.readLine()) != null) {
			Matcher m = pattern.matcher(line);
			if (m.find() && m.groupCount() > 0) {
				int overallPrice = Integer.parseInt(m.group(1));
				if (overallPrice == 0) break;
				return overallPrice;
			}
		}
		reader.close();
		return 0;
	}

	@Override
	public void onPaint(Graphics2D paint) {
		paint.setColor(Color.ORANGE);
		paint.drawString("Amount of time took to get bank wealth: " + formatT(endTime), 10, 310);
		paint.drawString("Amount of items found in bank: " + formatIntegers(getBank().getItems().length), 10, 325);
		paint.drawString("Bank amount: " + formatIntegers(wealth), 10, 340);
	}

	private String formatT(final long ms) {
		long s = ms / 1000, m = s / 60, h = m / 60;
		s %= 60;
		m %= 60;
		h %= 24;
		return String.format("%02d:%02d:%02d", h, m, s);
	}

	@Override
	public void onStart() {
		startTime = System.currentTimeMillis();
		if (getBank().isOpen()) {
			for (Item i : getBank().getItems()) {
				if (i != null){
					try {
						wealth = wealth + (getPrice(i.getId()) * i.getAmount());
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
			endTime = System.currentTimeMillis() - startTime;
		}
	}

	private String formatIntegers(int num) {
		return NumberFormat.getInstance().format(num);
	}

	@Override
	public int onLoop() throws InterruptedException {
		return 1000;
	}

}

made some changes hope u like

I was thinking about formatting the total wealth myself but just didn't get round it as I only wrote it to check the account wealth lol But thanks for this :)

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, crezzy said:

Thanks :) Nah it should never need to be updated  :D 

Why would I pay for something I can just program it myself?

can also add coins and tokens

wealth += i.getId() == 995 ? i.getAmount() : i.getId() == 13204 ? (i.getAmount() * 1000) : (getPrice(i.getId()) * i.getAmount());

 

  • Like 1

Share this post


Link to post
Share on other sites
On 3/22/2018 at 1:41 PM, Chris said:

can also add coins and tokens


wealth += i.getId() == 995 ? i.getAmount() : i.getId() == 13204 ? (i.getAmount() * 1000) : (getPrice(i.getId()) * i.getAmount());

 

I'm dumb didn't even occur to me to do that lmao /= Thanks though! When I open up eclipse I'll update it :) 

On 3/22/2018 at 11:11 PM, safe profile said:

Very nice script man, good job and thanks for sharing. Especially with source.

Cheers man and no worries :) 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...