eimxas999 Posted December 1, 2018 Share Posted December 1, 2018 Hello,so i want to get an active price of an item,what i thought is take a price of osrs url example : http://services.runescape.com/m=itemdb_oldschool/Green_dragonhide/viewitem?obj=1753 but thing is how do i make that? I mean script to pick up only the "price" thing? thank you everyone for the answers Quote Link to comment Share on other sites More sharing options...
R I F T Posted December 1, 2018 Share Posted December 1, 2018 (edited) 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 Edited December 1, 2018 by R I F T Quote Link to comment Share on other sites More sharing options...
LoudPacks Posted December 1, 2018 Share Posted December 1, 2018 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. 1 Quote Link to comment Share on other sites More sharing options...
eimxas999 Posted December 1, 2018 Author Share Posted December 1, 2018 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 ? Quote Link to comment Share on other sites More sharing options...
dormic Posted December 3, 2018 Share Posted December 3, 2018 (edited) 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 December 3, 2018 by dormic Quote Link to comment Share on other sites More sharing options...