Last active
March 11, 2020 20:49
-
-
Save thecoldicelander/994f8b729776212f16249e8be026a3cc to your computer and use it in GitHub Desktop.
Google sheets wrapper for GE with number formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
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)
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
To use you must first paste the script through "tools" -> "script editor" and save.
Saving seems to update the cache.