d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help Logging Auto-updating Data In Google Sheets
12Next
Add Reply New Topic New Poll
Member
Posts: 9,980
Joined: Feb 27 2009
Gold: 0.00
Mar 21 2016 03:02pm
Hello, so I made a Google Spreadsheet that imports data from a JSON api. This data updates maybe every 5-10 minutes. I was wondering if anyone knew of a way to log those values everytime on another page or something so that I can create a graph of changes over time.


This post was edited by Eliowns on Mar 21 2016 03:04pm
Member
Posts: 161,550
Joined: Oct 18 2006
Gold: 4.03
Warn: 20%
Mar 21 2016 05:18pm
google spreadsheets has history..

sounds like you're just asking for concatenation?

everytime that google spreadsheet gets updated, start on 1 row lower with the next data... derp
Member
Posts: 9,980
Joined: Feb 27 2009
Gold: 0.00
Mar 21 2016 06:05pm
Quote (GRATS @ Mar 21 2016 04:18pm)
google spreadsheets has history..

sounds like you're just asking for concatenation?

everytime that google spreadsheet gets updated, start on 1 row lower with the next data... derp


Thanks for the info. I have very little programming knowledge so I appreciate it.

Is there a way to automate the process so that it automatically logs it and moves down 1 row every time?
I looked up Concatenation and that appears to just merge two or more strings together, which I'm not sure how that would be used here.
Also if you don't want to hold my hand through this I would appreciate if you had a link with information so I can try to learn how to do this.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 21 2016 06:44pm
you said you already have a script that polls the site and puts the data in your spreadsheet. i assume you're specifying the cell? if you need to, put the cell number in A1, and that will tell you where to put it. then after your script runs, increment the value in A1

so the value of A1 will be B1 the first time, then B2, B3, B4....

This post was edited by carteblanche on Mar 21 2016 06:44pm
Member
Posts: 9,980
Joined: Feb 27 2009
Gold: 0.00
Mar 21 2016 07:46pm
Quote (carteblanche @ Mar 21 2016 05:44pm)
you said you already have a script that polls the site and puts the data in your spreadsheet. i assume you're specifying the cell? if you need to, put the cell number in A1, and that will tell you where to put it. then after your script runs, increment the value in A1

so the value of A1 will be B1 the first time, then B2, B3, B4....


Okay so lets say I have the data being put into the cell G4. You're saying I should make it so that cell A1=G4. Then after it updates it will be A2=G4(updated) and so on..
How would I go about making it increment like that?
Member
Posts: 161,550
Joined: Oct 18 2006
Gold: 4.03
Warn: 20%
Mar 22 2016 01:59am
Quote (Eliowns @ Mar 21 2016 06:46pm)
Okay so lets say I have the data being put into the cell G4. You're saying I should make it so that cell A1=G4. Then after it updates it will be A2=G4(updated) and so on..
How would I go about making it increment like that?


are you not able to post the code?
Member
Posts: 9,980
Joined: Feb 27 2009
Gold: 0.00
Mar 22 2016 04:39am
Quote (GRATS @ Mar 22 2016 12:59am)
are you not able to post the code?


The script I found to import JSON data is from Fast Fedora. It's pretty long so heres the github. https://github.com/fastfedora/google-docs

Then in the cell I use "=importJSON(url, query, parseOptions)

I am not personally updating the data. It updates automatically when it updates on the url I believe.

Again, this is my first time in the subforum so thanks for working with me!
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 22 2016 06:17pm
from a brief google search, looks like here's how you can set the value of a cell

Code
SpreadsheetApp.getActiveSheet().getRange('F2').setValue('Hello');


http://stackoverflow.com/questions/11334296/google-docs-script-set-cell-value

so i would create your own function which calls that formula you have. store the value in a variable. look at cell A1 to determine which cell to stick data in. stick it in there. increment A1.

something like so:

Code
// get the json data
var data = myfunction();
// A1 stores the row number of the last row we used. we will put data in the B column
var previousLocation = SpreadsheetApp.getActiveSheet().getRange('A1').getValue();
// increment it
var newLocation =previousLocation + 1;
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(newLocation);
// store the data in the next row
SpreadsheetApp.getActiveSheet().getRange("B" + newLocation).setValue(data);


if you wanna do some string parsing you can write B1 into the cell instead of writing 1 and concatenating with B later. but i gave a simple example to get you started.

This post was edited by carteblanche on Mar 22 2016 06:19pm
Member
Posts: 9,980
Joined: Feb 27 2009
Gold: 0.00
Mar 23 2016 03:38am
Quote (carteblanche @ Mar 22 2016 05:17pm)


Okay so I made a function using your code.

Code
function storeValue(){
// get the json data
var data = storeValue();
// A1 stores the row number of the last row we used. we will put data in the B column
var previousLocation = SpreadsheetApp.getActiveSheet().getRange('A1').getValue();
// increment it
var newLocation =previousLocation + 1;
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(newLocation);
// store the data in the next row
SpreadsheetApp.getActiveSheet().getRange("B" + newLocation).setValue(data);
}


With this function I would make it so that the cell A1
Code
=storeValue('Prices'!C4)
While 'Prices'!C4
Code
=importJSON(url, query, parseOptions)

This returns the error "Exceeded maximum stack depth (line 3)."
I googled this and found that the problem is that the function calls itself repeatedly until it hits the limit.

Is this correct?

I believe I understand the code you wrote and how to read it, especially with the helpful comments, but I can't for the life of my figure out how to write it.
I looked through the stackoverflow page you posted as well and played around with the code a bit but can't seem to figure out how to do it.

This post was edited by Eliowns on Mar 23 2016 03:39am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 23 2016 06:11am
Inside storeValue you are calling storeValue. this is infinite recursion, hence the stack overflow message. You're supposed to call your import json function in there

This post was edited by carteblanche on Mar 23 2016 06:33am
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll