-
Notifications
You must be signed in to change notification settings - Fork 2
/
Code.gs
78 lines (56 loc) · 2.02 KB
/
Code.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const ssID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';//sheet ssID, got to sheet -> share -> get link ->extract ID from link
const sheetLog='Log';
//one address = one new sheet
const sheetMeas=['Idena1','Idena2']; //sheet name
const IDNAaddress=['0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',//add here your IDNA wallet addresses
'0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'];
const sleepInterval= 2;//hours
const url='http://api.idena.io/api/Address/';
function getBalance(address,sheet) {
var response = UrlFetchApp.fetch(url+address, {muteHttpExceptions: true });
try {
var res = JSON.parse(response.getContentText());
if (res.result) {
const vals= res.result,
balance=vals.balance
stake=vals.stake;
let sum=parseFloat(balance)+parseFloat(stake);
SpreadsheetApp.openById (ssID) .getSheetByName(sheet).appendRow ([new Date (),balance, stake,sum]);
return;
}
SpreadsheetApp.openById (ssID) .getSheetByName(sheetLog).appendRow ([new Date (), 'Invalid response',res]);
return;
} catch (err) {
console.error (err.stack, err.message);
SpreadsheetApp.openById (ssID) .getSheetByName(sheetLog).appendRow ([new Date (), err.stack, err.message]);
}
return;
}
function update(){
for(var i=0,max=sheetMeas.length;i<max;i++)
getBalance(IDNAaddress[i],sheetMeas[i]);
}
function initTriggers(){
getAllTriggers();
deleteTriggers();
getAllTriggers();
update();
/*ScriptApp.newTrigger("update")
.timeBased()
.everyMinutes(60)
.create();*/
ScriptApp.newTrigger("update")
.timeBased()
.everyHours(sleepInterval)
.create();
getAllTriggers();
}
function deleteTriggers(){
var triggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < triggers.length; i++) {
ScriptApp.deleteTrigger(triggers[i]);
}
}
function getAllTriggers(){
Logger.log('Current script has ' + ScriptApp.getScriptTriggers().length + ' triggers.');
}