2017-10-14 48 views
0

我有,我想追加到谷歌片分析各種(JSON)API的數據源 - 最好是運行每隔一兩個小時旁邊一個時間戳。追加新的API數據,Google表格

我源格式,我發現如何使用在谷歌片觸發器,使其運行每一個「X」小時 - 其追加位的是我與掙扎。我猜我需要一些代碼來確定最後使用的行或列的位置,併爲下一個附加項添加一個代碼?

在數據源的術語和作爲此我使用此代碼的示例: http://blog.fastfedora.com/projects/import-json#ImportJSON和我的數據源(書籤交易)一個被提取爲這樣:

=ImportJSON("http://reddit.com/r/redditdev/about.json", "/data/url,/data/subscribers", "") 

這給出的輸出作爲如下:

Subscribers Url 
12114  /r/redditdev/ 

想結束時輸出我的樣子:

Url   TimeStamp    Subscribers 
/r/redditdev/ 14/10/2017 11:00:00 12114  
/r/redditdev/ 14/10/2017 12:00:00 12118 
/r/<others> x      y   

任何幫助表示讚賞!由於

回答

0

我寫了一個小reddit的履帶一會兒回來。好像這將有助於在這裏:​​github

不過來定製它一下做你尋找什麼:

var date = Utilities.formatDate(new Date(), "America/Los_Angeles", "dd/MM/yyyy HH:mm:ss"); 
var subs = json_twoDarray[1][0], //first index is row, second is column 
    url = json_twoDarray[1][1]; 
//Assuming there's a "sheet" variable for the sheet you are logging data to, 
//get one past the last row and the first three columns and set the values 
sheet.getRange(sheet.getLastRow + 1, 1, 1, 3).setValues([[url, date, subs]]); 

我也通常是新數據添加到電子表格,因此頂部最新的數據首先呈現,通常相當不錯。如果你想這樣做,你可以改變上面的代碼段的最後一行:

sheet.insertRowBefore(2); //Assuming the first row is headers, insert a new second row 
sheet.getRange(2,1,1,3).setValues([[url, date, subs]]); //add the data 

我沒有得到一個機會來測試這兩種片段,但他們應該工作。如果您有任何問題,請告訴我。