Skip to content

Instantly share code, notes, and snippets.

@thecoldicelander
Last active March 11, 2020 20:49
Show Gist options
  • Save thecoldicelander/994f8b729776212f16249e8be026a3cc to your computer and use it in GitHub Desktop.
Save thecoldicelander/994f8b729776212f16249e8be026a3cc to your computer and use it in GitHub Desktop.
Google sheets wrapper for GE with number formatting
var url = "http://services.runescape.com/m=itemdb_rs/api/graph/"
function ge(input,format,refresh) {
/*
Format defaults to true.
150.8K becomes 150800 so that math can be done on it.
*/
var raw_res = UrlFetchApp.fetch(url+input+".json",{muteHttpExceptions: true});
var res_status = raw_res.getResponseCode();
if(res_status !== 200){
if(res_status == 404){
return "item not found"
}else{
return "error with api"
}
}
var res_text = raw_res.getContentText();
var res_json = JSON.parse(res_text);
var timestamps = res_json.daily;
var highest_timestamp = Math.max.apply(null,Object.keys(timestamps));
var price = timestamps[highest_timestamp];
return parseInt(price);
}
@thecoldicelander
Copy link
Author

thecoldicelander commented Mar 11, 2020

To use you must first paste the script through "tools" -> "script editor" and save.

Saving seems to update the cache.

@thecoldicelander
Copy link
Author

I updated it to use the graph endpoint, Using Math.max to filter the highest timestamp in the object keys then using that one(As unix timestamps always count up)

@Noah-Jaffe
Copy link

Add a call to Math.random() so that the function doesn't get cashed. Also, set this to a trigger for every 4hrs or whatever interval it is that GE updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment