Skip to content

Instantly share code, notes, and snippets.

@matti
Last active December 13, 2021 15:55
Show Gist options
  • Save matti/6d768b33919100bd1031637051d453bc to your computer and use it in GitHub Desktop.
Save matti/6d768b33919100bd1031637051d453bc to your computer and use it in GitHub Desktop.
var ss = SpreadsheetApp.openById('1AKPTWbOiRactKDBxc-dA25JgWiXSjwKCK1ivVfa1xnw');
function minutely() {
run('minutely')
}
function hourly() {
run('hourly')
}
function daily() {
run('daily')
}
function monthly() {
run('monthly')
}
function run(name) {
var sheet = ss.getSheetByName(name)
var now = new Date()
var date = [
now.toDateString(),
now.toTimeString()
].join(" ")
var response = UrlFetchApp.fetch("https://explorer.raptoreum.com/api/getnodelist")
var status = response.getResponseCode()
if ( status != 200 ) {
Logger.log(["status", status])
return
}
var nodes = JSON.parse(response.getContentText())
var statuses = {}
for (let node of nodes) {
if ( !statuses[node.Status]) {
statuses[node.Status] = 0
}
statuses[node.Status] = statuses[node.Status] + 1
}
labels = sheet.getRange('B1:X1').getValues()[0]
row = [now]
for (let label of labels) {
if (label == '') {
break;
}
row.push(statuses[label])
}
Logger.log(row)
sheet.appendRow(row)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment