Author

Topic: 1st POST (Read 573 times)

newbie
Activity: 14
Merit: 0
August 22, 2013, 03:43:19 PM
#3
I have never played with the Google Docs scripts, but judging from the documentation, it does look very neat.
Just google for "Google Apps Script Spreadsheet Services", and you can get a full set of information on how to interact with the Google Spreadsheet.

member
Activity: 84
Merit: 10
Developer
August 22, 2013, 11:55:10 AM
#2
Here is what you wrote:

Code:
var range = ss.getSheets()[0].getRange("A1:A1");
var url = 'https://multipool.us/api.php?api_key=<12345_MYAPI_KEY_6789>';
var content = UrlFetchApp.fetch(url).getContentText();
var mydata = Utilities.jsonParse(content);
/* LTC */
  var datacut = mydata['currency']['ltc']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(datacut);
  var range = ss.getSheets()[0].getRange("A2:A2");
  var mydata = Utilities.jsonParse(content);
  var datacut = mydata['currency']['ltc']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(datacut);
  var range = ss.getSheets()[0].getRange("A3:A3");
  var mydata = Utilities.jsonParse(content);
  var datacut = mydata['currency']['ltc']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(datacut);


Sounds like you don't have much experience with json, I'll make this simple for you.  Above that section in your script put this:

Code:
function onOpen() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [ {name: "Refresh", functionName: "onOpen"} ];
  ss.addMenu("Update", menuEntries);

Then at the end you need to close the function with }

Now, lets say you want to pull your balances off of multipool -- then your entire code would look like this:

Code:

function onOpen() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [ {name: "Refresh", functionName: "onOpen"} ];
  ss.addMenu("Update", menuEntries);
var range = ss.getSheets()[0].getRange("A1:A1");
var url = 'https://multipool.us/api.php?api_key=<12345_MYAPI_KEY_6789>';
var content = UrlFetchApp.fetch(url).getContentText();
var ticker = Utilities.jsonParse(content);

 
  var price = ticker['currency']['ltc']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C41:C41");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['ltc']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E41:E41");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['ltc']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
  
  var range = ss.getSheets()[0].getRange("B42:B42");
  var price = ticker['currency']['nvc']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C42:C42");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['nvc']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E42:E42");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['nvc']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
  
  var range = ss.getSheets()[0].getRange("B43:B43");
  var price = ticker['currency']['ftc']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C43:C43");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['ftc']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E43:E43");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['ftc']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
  
  var range = ss.getSheets()[0].getRange("B44:B44");
  var price = ticker['currency']['mnc']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C44:C44");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['mnc']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E44:E44");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['mnc']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
  
  var range = ss.getSheets()[0].getRange("B45:B45");
  var price = ticker['currency']['wdc']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C45:C45");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['wdc']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E45:E45");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['wdc']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
  
  var range = ss.getSheets()[0].getRange("B46:B46");
  var price = ticker['currency']['dgc']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C46:C46");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['dgc']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E46:E46");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['dgc']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
  
  var range = ss.getSheets()[0].getRange("B47:B47");
  var price = ticker['currency']['lky']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C47:C47");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['lky']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E47:E47");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['lky']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
 
  var range = ss.getSheets()[0].getRange("B48:B48");
  var price = ticker['currency']['arg']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C48:C48");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['arg']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E48:E48");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['arg']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
  
  var range = ss.getSheets()[0].getRange("B49:B49");
  var price = ticker['currency']['pxc']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C49:C49");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['pxc']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E49:E49");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['pxc']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
  
  var range = ss.getSheets()[0].getRange("B50:B50");
  var price = ticker['currency']['mec']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C50:C50");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['mec']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E50:E50");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['mec']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
  
  var range = ss.getSheets()[0].getRange("B51:B51");
  var price = ticker['currency']['cap']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C51:C51");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['cap']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E51:E51");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['cap']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  
  
  var range = ss.getSheets()[0].getRange("B52:B52");
  var price = ticker['currency']['cgb']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("C52:C52");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['cgb']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);
  var range = ss.getSheets()[0].getRange("E52:E52");
  var ticker = Utilities.jsonParse(content);
  var price = ticker['currency']['cgb']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(price);

}

You'll have to change the getRange values to fit your needs.  This will give you the confirmed rewards, estimated rewards and your current hash rate on whichever coin you are mining.. Some of the code is unneeded, but I generated it with a different script instead of rewriting each coin.
newbie
Activity: 8
Merit: 0
August 12, 2013, 07:20:59 AM
#1
Hi all

I was reading a post on this forum about the use of google spreadsheet, JSON and API key:

https://bitcointalk.org/index.php?PHPSESSID=r99941oq967hvd3uk0nfrj51h6&topic=167635.2260

Well, I'd like to ask directly to the author but I cannot for my  newbie status ...  so here I am.
I have to admit I know NOTHING about JAVA scripts so please excuse my incompetence 
This Are steps I tried to follow
I've  opened a new  spreadsheet in google docs then I  selected tools >>  manage script >>  new
I copied and past the code the author suggested (down here), I  set my api key  and tried to click run function ...  the page blame about "ss" is not defined .

Any suggestion or link to howto/guide to help this old donk (aka me)     will be appreciated.
TNX in advance for your help




   
ReferenceError: "ss" non definito. (riga 9, file "Codice")


CODE 



var range = ss.getSheets()[0].getRange("A1:A1");
var url = 'https://multipool.us/api.php?api_key=<12345_MYAPI_KEY_6789>';
var content = UrlFetchApp.fetch(url).getContentText();
var mydata = Utilities.jsonParse(content);
/* LTC */
  var datacut = mydata['currency']['ltc']['confirmed_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(datacut);
  var range = ss.getSheets()[0].getRange("A2:A2");
  var mydata = Utilities.jsonParse(content);
  var datacut = mydata['currency']['ltc']['estimated_rewards'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(datacut);
  var range = ss.getSheets()[0].getRange("A3:A3");
  var mydata = Utilities.jsonParse(content);
  var datacut = mydata['currency']['ltc']['hashrate'];
     SpreadsheetApp.setActiveRange(range);
     SpreadsheetApp.getActiveRange().setValue(datacut);

Jump to: