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.

Get item price from osrs url?

Featured Replies

package com.loudpacks.rs;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.loudpacks.util.IOUtils;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class ItemLookup
{
	private static final String API_LOCATION = "http://services.runescape.com/m=itemdb_oldschool" +
		"/api/catalogue/detail.json?item=%d";

	private static final long TEN_MINUTES = 600000;
	private static final Map<Integer, LookupResult> cache = new HashMap<>();
	private static Map<String, Integer> itemMap;
	private static long startTime;

	static
	{
		startTime = System.currentTimeMillis();
		itemMap = IOUtils.loadItemMap(); //I dumped the cache and generated a map <itemName, itemID> so I can lookup items by name instead of id
	}

	public static int getIdForName(String name)
	{
		if(!itemMap.containsKey(name))
			return -1;
		return itemMap.get(name);
	}

	private static LookupResult parse(int itemId, String json)
	{

		Gson gson = new Gson();
		JsonObject body = gson.fromJson(json, JsonObject.class);
		JsonObject item = body.getAsJsonObject("item");
		JsonObject current = item.getAsJsonObject("current");

		return new LookupResult(
			item.get("icon").getAsString(),
			item.get("icon_large").getAsString(),
			item.get("type").getAsString(),
			item.get("typeIcon").getAsString(),
			item.get("name").getAsString(),
			item.get("description").getAsString(),
			itemId,
			current.get("price").getAsString()
		);
	}

	private static void flushCache()
	{
		if (cache != null)
		{
			cache.clear();
		}
	}

	public static LookupResult find(int itemId)
	{
		if ((System.currentTimeMillis() - TEN_MINUTES) > startTime)
		{
			flushCache();
			startTime = System.currentTimeMillis();
		}

		if (cache != null && !cache.isEmpty())
		{
			LookupResult result = cache.get(itemId);
			if (result != null)
			{
				return result;
			}
		}

		String json;
		try
		{
			URL url = new URL(String.format(API_LOCATION, itemId));
			Scanner scan = new Scanner(url.openStream()).useDelimiter("\\A");
			json = scan.next();
			scan.close();
		}
		catch (IOException e)
		{
			return null;
		}

		LookupResult result = parse(itemId, json);

		if (cache != null)
		{
			cache.put(itemId, result);
		}

		return result;
	}
}
package com.loudpacks.rs;

import lombok.Getter;

public class LookupResult
{
	@Getter
	private final String smallIconUrl, largeIconUrl, type, typeIcon, name, itemDescription;
	@Getter
	private final int id;
	@Getter
	private final String price;

	protected LookupResult(String smallIconUrl,
						   String largeIconUrl,
						   String type,
						   String typeIcon,
						   String name,
						   String itemDescription,
						   int id,
						   String price)
	{

		this.smallIconUrl = smallIconUrl;
		this.largeIconUrl = largeIconUrl;
		this.type = type;
		this.typeIcon = typeIcon;
		this.name = name;
		this.itemDescription = itemDescription;
		this.id = id;
		this.price = price;
	}
}

Some code from a project I was working on. Should be enough to get you started.

  • Author
52 minutes ago, R I F T said:

3 years ago but I believe nothings changed -> https://www.reddit.com/r/2007scape/comments/3g06rq/guide_using_the_old_school_ge_page_api/

Should be able to get it working with a bit of Googling on how to send the requests / parse JSON responses

ummm well,that reddit post is.. cant really say worthless,but what i think is:

you define url as a string

String url = "google.com";

then somehow get the text from the url,and thats it ?

package osbot_scripts.framework;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public class GEPrice {

	private static final String BASE = "https://api.rsbuddy.com/grandExchange?a=guidePrice&i=";

	/**
	 * Default Constructor
	 * 
	 */
	public GEPrice() {

	}

	/**
	 * Gets the overall price of an item.
	 * 
	 * @param itemID
	 * @return itemPrice
	 * @throws IOException
	 */
	public int getOverallPrice(final int itemID) throws IOException {
		return parse(itemID, "overall");
	}

	/**
	 * Gets the buying price of an item.
	 * 
	 * @param itemID
	 * @return itemPrice
	 * @throws IOException
	 */
	public int getBuyingPrice(final int itemID) throws IOException {
		return parse(itemID, "buying");
	}

	/**
	 * Gets the selling price of an item.
	 * 
	 * @param itemID
	 * @return itemPrice
	 * @throws IOException
	 */
	public int getSellingPrice(final int itemID) throws IOException {
		return parse(itemID, "selling");
	}

	/**
	 * Retrieves the price of an item.
	 * 
	 * @param itemID
	 * @return itemPrice
	 * @throws IOException
	 */
	private int parse(final int itemID, String choice) throws IOException {
		final URL url = new URL(BASE + itemID);
		BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream()));
		String line;
		String price = null;
		while ((line = file.readLine()) != null) {
			if (line.contains("{")) {
				price = (line).trim();
			}
		}
		if (choice.equals("buying")) {
			price = price.substring(price.indexOf(",") + 10, nthOccurrence(price, ',', 1)).trim();
		} else if (choice.equals("selling")) {
			price = price.substring(nthOccurrence(price, ',', 2) + 11, price.indexOf("sellingQuantity") - 2).trim();
		} else {
			price = price.substring(price.indexOf(":") + 1, price.indexOf(",")).trim();
		}
		file.close();
		return Integer.parseInt(price);
	}

	private int nthOccurrence(String str, char c, int n) {
		int pos = str.indexOf(c, 0);
		while (n-- > 0 && pos != -1)
			pos = str.indexOf(c, pos + 1);
		return pos;
	}
}

From DoricsQuester, not sure who made it but seems pretty clean. To use it you can use the following:

GEPrice grandExchangePrices = new GEPrice();

int price = grandExchangePrices.getBuyingPrice(1028);

log(price);

 

Edited by dormic

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.