Jump to content

Spork's Simple GE Dumper


Recommended Posts

Posted (edited)

A buddy of mine requested this over Skype, and as I already had it written as a CLI app, I just converted it to work with OSBot. I guess it's nice for the GUI but not very resource friendly haha.

 

The script iterates through IDs on the GE, checking if it's valid or nah, and then simply log()'s them. Pls write your own logger if you actually want to make use of it lmao.

 

EDIT/WARN: Due to osrs website, this code currently does not work. Will have to change useragent later on and probably use Apache's web lib in further edits. Pls donot use dis for anything other than an example. :D

 

Jar: http://www.filedropper.com/osgedump

 

Code:

package main;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

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.util.regex.Matcher;
import java.util.regex.Pattern;

@ScriptManifest(name = "Simple GE Dumper", author = "Spork", version = 13.37, info = "Creates prices.txt...", logo = "")

public class Main extends Script {

	/*
	 * Simple GE Dumper
	 * Should start running at item 0, which is invalid anyway...
	 * Good luck!
	 */
	
	String BASE_URL = "http://services.runescape.com/m=itemdb_oldschool/lookup/viewitem?obj=";

	int itemId;
	State state;

	public enum State {
		STARTUP, VALID, INVALID, ERROR
	}

	@[member='Override']
	public void onStart() {
		state = State.STARTUP;
		itemId = 0;

	}

	@[member='Override']
	public void onExit() {
		//Maybe gonna put logging here.
	}

	@[member='Override']
	public int onLoop() {
		try (final BufferedReader reader = new BufferedReader(//Creates BufferedReader
				new InputStreamReader(new URL(new StringBuffer(BASE_URL).append(itemId).toString()).openStream()))) { //Creates InputStream for the URL to GE appending itemId onto it

			if (reader.toString().contains("Sorry, there was a problem with your request.")) {
				state = State.INVALID; //The item is unavailable or not a tradable item
			} else {
				state = State.VALID; //WOO
				String name = getBetween(reader.toString(), "<title>", " - "); //Most useful function: getBetween()
				String price = getBetween(reader.toString(), "Current Guide Price <span title='", "'");
				log(name + " " + price); //TODO: Logging to file
			}
		} catch (MalformedURLException e) {
			state = State.ERROR;
		} catch (IOException e) {
			state = State.ERROR;
		}
		if (state == State.ERROR) {
			try {
				sleep(5000); //Sleep for a while so you can look at it and be like ?? y
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		itemId++;//Next iteration
		return 100;
	}

	@[member='Override']
	public void onPaint(Graphics2D g) {
		// This is where you will put your code for paint(s)

		g.drawString("Status: " + state, 30, 300);
		g.drawString("Checking Item: " + itemId, 30, 280);

	}

	public static String getBetween(String haystack, String pre, String post) {
		Pattern pattern = Pattern.compile(Pattern.quote(pre) + "(.+?)" + Pattern.quote(post));
		Matcher matcher = pattern.matcher(haystack);

		if (matcher.find()) {
			return haystack.substring(matcher.start(1), matcher.end(1));
		}

		return "No match could be found.";
	}
}
Edited by Spork
  • Like 1
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...