Jump to content

Grab price from OSB


lisabe96

Recommended Posts

You would hook their API system.

But if im not mistaken they have no intention of making a public one. (you COULD pull the one they have from the webpage though?)
not sure what the requests would look like or how fast/slow it'd be.

 

<title>OSBuddy Exchange</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link rel="stylesheet" href="https://rsbuddy.com/static/exchange/css/exchange.css">
<script src="https://rsbuddy.com/static/js/js.cookie-2.0.3.min.js"></script>
<script src="https://rsbuddy.com/static/js/handlebars-v3.0.0.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
        $(function () {
            $(".patch-template").each(function (idx, element) {
                var id = $(this).attr("id");
                $.get("https://rsbuddy.com/static/exchange/templates/" + id + ".html", function (html) {
                    $("#" + id).html(html);
                });
            });
        });
    </script>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script type="text/javascript">
        STATIC_BASE = "https://rsbuddy.com/static";
        BASE_URL = "https://rsbuddy.com/osbuddy";
        API_BASE_URL = "https://api.rsbuddy.com";
        SITE_BASE_URL = "https://rsbuddy.com";
        SESSION_ID = "c6b1d6ee-0c42-4b17-afc7-d934a6a006c4";
    </script>
Edited by OurSickStory
Link to comment
Share on other sites

Shit code, didn't know how to do it too first and this was my first try on it. Here you go. I dumped all item prices using this

 

	public static TreeMap<Integer, Integer> dump_map = new TreeMap<Integer, Integer>();
	public static HashMap<Integer, Integer> current_item_map = new HashMap<Integer, Integer>();

	public static void main(String[] args) throws IOException {
		toTreeMap();

	}

	/**
	 * 
	 * @param itemId
	 * @return price of the item
	 */
	public static int getPrice(int itemId) {
		try {
			URL url = new URL("https://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + itemId);
			try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
				String line = reader.readLine();
				return line == null ? -1 : Integer.parseInt(line.substring(11, line.indexOf(',')));
			} catch (IOException e) {
				e.printStackTrace();
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}

		return -1;
	}

	/**
	 * 
	 * @param val
	 * @throws IOException
	 * 
	 */
	public static void getItems() throws IOException {
		int count = 0;
		try {
			FileReader in = new FileReader(System.getProperty("user.home") + "/Dump.txt");
			BufferedReader br = new BufferedReader(in);
			String line = br.readLine();
			while (line != null) {
				System.out.println(line);
				count++;
				line = br.readLine();
			}
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 * @param id
	 * @return priceFromFile
	 */
	public static Integer getPriceFromFile(int id) {
		try {
			FileReader in = new FileReader(System.getProperty("user.home") + "/Dump.txt");

			BufferedReader br = new BufferedReader(in);
			String line = br.readLine();
			while (line != null && !line.contains(Integer.toString(id))) {
				line = br.readLine();
			}
			String content = line.substring(line.lastIndexOf(' ') + 1);
			in.close();
			System.out.println(id + " >" + Integer.parseInt(content) + "<");
			return line.lastIndexOf(Integer.parseInt(content));

		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

	/**
	 * 
	 * @param val
	 * @return Text file with items from @param.
	 */
	public static void grabItems(int val) {
		for (int i = 1; i < 13193; i++) {
			try {
				File file = new File(System.getProperty("user.home") + "/Dump.txt");

				if (!file.exists()) {
					file.createNewFile();
				}

				FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
				BufferedWriter bw = new BufferedWriter(fw);
				bw.newLine();
				while (getPrice(i) < val) {
					i++;
				}
				System.out.println(i + " Value: " + getPrice(i));
				bw.write(i + " " + getPrice(i));
				bw.flush();
				bw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * @return all items into a treeMap.
	 */
	public static void toTreeMap() {
		String filePath = System.getProperty("user.home") + "/Dump.txt";
		try {
			String line;
			BufferedReader br = new BufferedReader(new FileReader(filePath));
			while ((line = br.readLine()) != null) {
				String[] parts = line.split(" ", 2);
				if (parts.length >= 2) {
					int key = Integer.parseInt(parts[0]);
					int value = Integer.parseInt(parts[1]);
					dump_map.put(key, value);
					System.out.println(dump_map.put(key, value));
				} else {
					System.out.println("Ingoring line.");
				}
			}
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void getKeys() {
		toTreeMap();
		Set<Integer> keys = dump_map.keySet();
		System.out.println(keys);
	}

	public static <K, V extends Comparable<? super V>> SortedSet<Map.Entry<K, V>> entriesSortedByValues(Map<K, V> map) {
		SortedSet<Map.Entry<K, V>> sortedEntries = new TreeSet<Map.Entry<K, V>>(new Comparator<Map.Entry<K, V>>() {
			@Override
			public int compare(Map.Entry<K, V> e1, Map.Entry<K, V> e2) {
				int res = e1.getValue().compareTo(e2.getValue());
				return res != 0 ? res : 1;
			}
		});
		sortedEntries.addAll(map.entrySet());
		return sortedEntries;
	}

	public static void getHighestValue() {
		toTreeMap();
		for (Entry<Integer, Integer> entry : entriesSortedByValues(dump_map)) {
			System.out.println(entry.getKey() + ":" + entry.getValue());
		}
	}

EDIT: yeah. It's shit but works. If I were you I wouldn't use it in my script. Edited by Psvxe
Link to comment
Share on other sites

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

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

	    public int getOverallPrice(int itemID) throws IOException {
	        return this.parse(itemID, "overall");
	    }

	    public int getBuyingPrice(int itemID) throws IOException {
	        return this.parse(itemID, "buying");
	    }

	    public int getSellingPrice(int itemID) throws IOException {
	        return this.parse(itemID, "selling");
	    }

	    private int parse(int itemID, String choice) throws IOException {
	        String line;
	        URL url = new URL("https://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + itemID);
	        BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream()));
	        String price = null;
	        while ((line = file.readLine()) != null) {
	            if (!line.contains("{")) continue;
	            price = line.trim();
	        }
	        price = choice.equals("buying") ? price.substring(price.indexOf(",") + 10, this.nthOccurrence(price, ',', 1)).trim() : (choice.equals("selling") ? price.substring(this.nthOccurrence(price, ',', 2) + 11, price.indexOf("sellingQuantity") - 2).trim() : 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;
	    }
}

Then you use it like so:

public class Main extends Script{
    Price price = Price();
    int priceOfItem;
    public void onStart(){
    priceOfItem = price.getSellingPrice(ITEMID);
    }
}
  • Like 1
Link to comment
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.
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...