Thread: Protection Values Update API

Results 1 to 5 of 5
  1. #1 Protection Values Update API 
    BoomScape #1
    BoomScape's Avatar
    Join Date
    May 2013
    Posts
    2,422
    Thanks given
    289
    Thanks received
    234
    Rep Power
    48
    This will basically update or add 'protect_value' to your item_info.json based on OSRS Grand Exchange prices, the API was mostly written using the OpenAI ChatGPT just to see what it could do inputting text, if you haven't already checked it out I'd recommend giving it a go and seeing what you can get it to do! OpenAI ChatGPT

    Code:
    package io.ruin.api.utils;
    
    import com.fasterxml.jackson.databind.JsonNode;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.fasterxml.jackson.databind.node.ObjectNode;
    
    import java.io.*;
    import java.net.URL;
    import java.net.URLConnection;
    
    public enum GrandExchangeAPI {
    
        BOFA(25862, 25865, 25867, 25869, 25884, 25886, 25888, 25890, 25892, 25894, 25896),
        BLADE_OF_SAELDOR(23997, 23995, 24551, 24553, 25870, 25872, 25874, 25876, 25878, 25880, 25882),
        BRACELET_ETHERUEM(21817, 21816),
        SANGUINESTI_STAFF(22481, 22323, 25731, 25733, 25739),
        SCYTHE_OF_VITUR(22486, 22325, 22664, 25736, 25738, 25739, 25741),
        SERPENTINE_HELM(12929, 12931, 13198, 13199, 13196, 13197),
        TOXIC_STAFF(12902, 12904),
        TOXIC_BLOWPIPE(12924, 12926),
        TOME_OF_FIRE(20716, 20714),
        CRAWS_BOW(22547, 22550),
        THAMMARONS_SCEPTRE(22552, 22555),
        VIGGORAS_CHAINMACE(22542, 22545),
        TRIDENT(11905, 11907),
        TRIDENT_E(22290, 22288),
        TOXIC_TRIDENT(12900, 12899),
        TOXIC_TRIDENT_E(22294, 22292);
    
    
        int unchargedId;
        int[] chargedIds;
    
        GrandExchangeAPI(int unchargedId, int... chargedIds) {
            this.unchargedId = unchargedId;
            this.chargedIds = chargedIds;
        }
    
    
        public static void main(String[] args) throws IOException {
    
            URL url = new URL("https://prices.runescape.wiki/api/v1/osrs/latest");
    
            URLConnection conn = url.openConnection();
            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0");
    
            // Read the response from the API
            ObjectMapper apiMapper = new ObjectMapper();
            JsonNode apiRoot = apiMapper.readTree(conn.getInputStream());
    
            // Parse the JSON file
            ObjectMapper mapper = new ObjectMapper();
            JsonNode root = mapper.readTree(new File("./boomscape-game-server/data/items/item_info.json"));
    
            // Iterate through the list of items
            for (JsonNode item : root) {
                int id = item.path("id").asInt();
                int currentPrice = item.path("protect_value").asInt();
    
                for (GrandExchangeAPI grandExchangeAPI : GrandExchangeAPI.values())
                    for (int chargedIds : grandExchangeAPI.chargedIds)
                        if (chargedIds == id)
                            id = grandExchangeAPI.unchargedId;
    
                JsonNode lowNumber = apiRoot.path("data").path(String.valueOf(id)).path("low");
                JsonNode highNumber = apiRoot.path("data").path(String.valueOf(id)).path("high");
                int price = (highNumber.asInt() + lowNumber.asInt()) / 2;
    
                if (price == 0)
                    continue;
    
                // Update the 'protect_value' for the current item
                ((ObjectNode) item).put("protect_value", price);
    
                String currentPriceComparison = currentPrice > 0 ? String.valueOf(currentPrice) : "Unset";
                //System.out.println("ID:" + id + ", Current price: " + currentPriceComparison + ", New price: " + low);
            }
    
            // Write the updated JSON data to a new file
            mapper.writerWithDefaultPrettyPrinter().writeValue(new File("./boomscape-game-server/data/items/item_info_updated.json"), root);
            System.out.println("Successfully updated Protection Values for Item Info");
        }
    }
    Attached image
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    26
    Posts
    5,103
    Thanks given
    1,818
    Thanks received
    1,767
    Rep Power
    2438
    Interesting snippet, care to share the prompts you used to generate the code?
    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Spoiler for skrrrrr:

    Attached image
    Reply With Quote  
     

  4. Thankful user:


  5. #3  
    ☕ABERRANT☕

    Join Date
    Oct 2015
    Posts
    98
    Thanks given
    101
    Thanks received
    17
    Rep Power
    67
    I was thinking about experimenting with this technology the other day to see what its capabilities are, and if there are any use cases within the RSPS' scene. Interesting to see someone else had the same idea.

    Anything else you've tried with this?
    Attached image
    Reply With Quote  
     

  6. #4  
    BoomScape #1
    BoomScape's Avatar
    Join Date
    May 2013
    Posts
    2,422
    Thanks given
    289
    Thanks received
    234
    Rep Power
    48
    Quote Originally Posted by Tyluur View Post
    Interesting snippet, care to share the prompts you used to generate the code?
    Unfortunately I don't have any of the prompts now, but something along the lines of this;

    Write me an API that uses the results from 'https://prices.runescape.wiki/api/v1/osrs/latest' which uses an existing JSON saved locally using the 'ids' saved within that JSON to match against the APIs list, and then update the 'protect_value' based on the 'high' result, or add the 'protect_value' information.

    It's not exact, but it was along the lines of that, with a few extra prompts to make it exactly how I wanted it. The whole process took about 30 minutes. The ChatGPT tool is extremely interesting to play with, initially I just asked it to write me an API that gets the OldSchool RuneScape item prices and update the json, and it found the correct API URL to use on it's own and provided the code which worked, though the official API URL has a limit where after x amount of requests you start receiving white pages instead of the items information.

    Quote Originally Posted by Spadow View Post
    I was thinking about experimenting with this technology the other day to see what its capabilities are, and if there are any use cases within the RSPS' scene. Interesting to see someone else had the same idea.

    Anything else you've tried with this?
    I've tried a lot but not so much todo with 'RSPS' mainly for writing API's & WordPress Plugins. Not sure how it'd get on with RSPS related things as it wouldn't know the framework. You'd have better luck with more generic things, or asking it to write the 'base' of the code on which you can work on top off.

    You can also paste current code you have into it and ask it to write it in a better format, though ChatGPT seems to have a limit on the information it feeds back to you sometimes as it'll write half the code and stop!

    I've seen people on YouTube ask ChatGPT to write things such as making an App that functions and looks like Twitter, and it seemed to do the majority of the code with the guy having to input some minor parts himself.

    Overall it's an extremely powerful and interesting tool, defo worth trying out and seeing what you can get out of it whilst it's free!
    Attached image
    Reply With Quote  
     

  7. Thankful users:


  8. #5  
    ☕ABERRANT☕

    Join Date
    Oct 2015
    Posts
    98
    Thanks given
    101
    Thanks received
    17
    Rep Power
    67
    Quote Originally Posted by BoomScape View Post
    Unfortunately I don't have any of the prompts now, but something along the lines of this;

    Write me an API that uses the results from 'https://prices.runescape.wiki/api/v1/osrs/latest' which uses an existing JSON saved locally using the 'ids' saved within that JSON to match against the APIs list, and then update the 'protect_value' based on the 'high' result, or add the 'protect_value' information.

    It's not exact, but it was along the lines of that, with a few extra prompts to make it exactly how I wanted it. The whole process took about 30 minutes. The ChatGPT tool is extremely interesting to play with, initially I just asked it to write me an API that gets the OldSchool RuneScape item prices and update the json, and it found the correct API URL to use on it's own and provided the code which worked, though the official API URL has a limit where after x amount of requests you start receiving white pages instead of the items information.



    I've tried a lot but not so much todo with 'RSPS' mainly for writing API's & WordPress Plugins. Not sure how it'd get on with RSPS related things as it wouldn't know the framework. You'd have better luck with more generic things, or asking it to write the 'base' of the code on which you can work on top off.

    You can also paste current code you have into it and ask it to write it in a better format, though ChatGPT seems to have a limit on the information it feeds back to you sometimes as it'll write half the code and stop!

    I've seen people on YouTube ask ChatGPT to write things such as making an App that functions and looks like Twitter, and it seemed to do the majority of the code with the guy having to input some minor parts himself.

    Overall it's an extremely powerful and interesting tool, defo worth trying out and seeing what you can get out of it whilst it's free!
    Definitely going to look more into this and see what I can come up with, Thank you so much for the information you have given.
    Attached image
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Error after updating read values
    By mamads in forum Help
    Replies: 3
    Last Post: 08-05-2018, 04:06 AM
  2. read value update
    By Plo Koon in forum Buying
    Replies: 6
    Last Post: 03-17-2018, 12:26 AM
  3. Replies: 24
    Last Post: 03-03-2015, 04:02 PM
  4. [PI] item protect value
    By aceflare0 in forum Help
    Replies: 0
    Last Post: 02-21-2013, 08:17 AM
  5. Password Protect Pages: Updated
    By Jay Dawg in forum Website Development
    Replies: 18
    Last Post: 07-08-2010, 05:02 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •