Jump to content

Spork's Simple GE Dumper


Spork

Recommended Posts

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
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

  • Recently Browsing   0 members

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