jamietr1 / google-docs-writing-tracker

Automation scripts to track writing in Google Docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot find method formatDate(string,string,string). (line 480, file "Code") & Cannot find folder Sandbox. (line 119, file "Code")

rustuptwist opened this issue · comments

I received these two issues via email this morning. After looking back at the script in the 'writingStats' script I noticed some (alleged) discrepancies. Note I am far from understanding programming so it may well be me.

I did notice that on the ReadMe page you did mention to create certain folders of which i left out one (or 2 if you consider the SNAPSHOT_FOLDER). I named mine 'Snapshot' as opposed to what you have.

So below is the question.

Q: Should the folder be named ‘Sandbox/Earlier’ as you have in the documentation or ‘(SNAPSHOT_FOLDER)’ as it is in the script itself? I received an error message about line 119, so I assume my folder title is incorrect.

I will re-configure the files as I think you intend them to be configured. One thing that does stick out is that I set my location setting to (+3:00) Riyadh but the file/doc has them as same time zone but named Nairobi, e.g. (+3:00) Nairobi.

On the formatDate issue, I just want to verify that the spreadsheet and the script files all have the same timezone set.

On the folder issue, you can call the folders whatever you want, so long as you have put the names in the appropriate place on the Config tab. That is where the scripts will look. Keep in mind that just typing the folder names in those cells doesn't create the folder. That you have to do separately. Once the folders are created and the config tab is set up with values that point to their path, you should be good.

Ok, let me again say I am not adept at programming so perhaps it may be better if I seek out an IRC for these questions. So let me know...
As for the timezone, in the 'Writing Stats' code.gs page i see instances of TIME_ZONE '"yyyy-MM-dd" (lines 131, 135, 153) whereas in the the DailyAlmanac code.gs page it isTIME_ZONE "MM/dd/yyyy (line 92). Again since no one is reporting problems I assume it is me.
As for the folder issue, yes indeed the folders are created and name according to your conventions although while looking thru one of the script files i did see this in 'WritingSTats (code.gs) page on line 310 & 313 "var folder = DocsList.getFolder(SNAPSHOT_FOLDER).
It was there on line 119 but my folder is named Sandbox/Earlier so I am assuming i should rename those instances on lines 310 & 313 as well?

@rustuptwist You should not have to change any of the code.

For the folder, you just need to set your folders on the Config tab of the spreadsheet, like this:

google_writing_tracker_data

That's all there is to it. The values you put in the yellow box are the location of the folders You can call them whatever you want. You shouldn't change any of the code for this.

For the timezone issue, you shouldn't need to change the code either. What you need to do is make sure that the timezone setting on the spreadsheet is set to the same timezone as both of the script files. You can find the former setting in the File menu...Spreadsheet settings...:

google_writing_tracker_data

For the script files, you'll find the timezone settings in File... Project Properties...

image

For both of these things, you shouldn't have to touch the code at all.

Ok so I am going to delete everything, all files and then start over fresh. Although time consuming, I think it is best, especially since you mentioned I should not have to change anything within the script. I am confused though. You say that the folders don't need to be name 'Sandbox' or 'Sandbox/Earlier'? Also I think i understand that the files that are fiction or non-fiction need to have the words in {{brackets}} in order to be counted correctly. Does the same apply for 'blogging' writing?

BTW, I received basically the same error as the previous which is why i plan to start over from scratch. :)

@rustuptwist The current release don't implement the blogging function publicly. So it is just a place-holder for future use.

Not sure why my "Writings" spreadsheet file id does not contain 'ccc?key='
I am only getting this file ID from it: 'spreadsheets/1hkDKXaDr2awryh5ZWFEfTjd90O6r92P0PyK8oiE-h0Q/edit#gid=0' so I used: '1hkDKXaDr2awryh5ZWFEfTjd90O6r92P0PyK8oiE-h0Q/' as my file ID.

That looks right to me.


Jamie Todd Rubin (@jamietr http://twitter.com/jamietr)
http://www.jamietoddrubin.com
http://www.jamietoddrubin.com/going-paperless/

On Sun, Aug 10, 2014 at 3:00 PM, dawoud williams notifications@github.com
wrote:

Not sure why my "Writings" spreadsheet file id does not contain 'ccc?key='
I am only getting this file ID from it:
'spreadsheets/1hkDKXaDr2awryh5ZWFEfTjd90O6r92P0PyK8oiE-h0Q/edit#gid=0' so I
used: '1hkDKXaDr2awryh5ZWFEfTjd90O6r92P0PyK8oiE-h0Q/' as my file ID.


Reply to this email directly or view it on GitHub
#16 (comment)
.

I am assuming that i substitute 'GMT' in place of EST since my time zone is described as GMT+03:00. Correct?

Timezones shouldn't be hardcoded anywhere, unless you are not using the
beta version. In the beta version, all you need to do is ensure the
timezone on the scripts and spreadsheet is set properly per the
instruction. If you are not using the beta version, that may be the issue.
I'd recommend using the beta. I'll be pushing it to production later today.
(I'm on a plane right now and hesitate to do it while in the air, in case I
lose my WiFi connection.)


Jamie Todd Rubin (@jamietr http://twitter.com/jamietr)
http://www.jamietoddrubin.com
http://www.jamietoddrubin.com/going-paperless/

On Sun, Aug 10, 2014 at 3:09 PM, dawoud williams notifications@github.com
wrote:

I am assuming that i substitute 'GMT' in place of EST since my time zone
is described as GMT+03:00. Correct?


Reply to this email directly or view it on GitHub
#16 (comment)
.

My apologies for the slew of questions, as I know you said you were unable to offer much support...
I was wondering on the 'Your Writing Data spreadsheet will need to be configured with several new tabs' are you referring here to the 'Writing' spreadsheet that has the 'Date' and 'Words' or creating an entirely new spreadsheet? thx

P.S. I am following the directions from this page: https://github.com/jamietr1/google-docs-writing-tracker/blob/master/README.md

Okay, that explains the problems you were having. I was assuming you were
using the Beta. Do me a favor, wait a few hours until I push the beta into
production, and then check out the very different README you will see
there. It will make much more sense. My bad.


Jamie Todd Rubin (@jamietr http://twitter.com/jamietr)
http://www.jamietoddrubin.com
http://www.jamietoddrubin.com/going-paperless/

On Sun, Aug 10, 2014 at 3:16 PM, dawoud williams notifications@github.com
wrote:

My apologies for the slew of questions, as I know you said you were unable
to offer much support...
I was wondering on the 'Your Writing Data spreadsheet will need to be
configured with several new tabs' are you referring here to the 'Writing'
spreadsheet that has the 'Date' and 'Words' or creating an entirely new
spreadsheet? thx

P.S. I am following the directions from this page:
https://github.com/jamietr1/google-docs-writing-tracker/blob/master/README.md


Reply to this email directly or view it on GitHub
#16 (comment)
.

Ha, Ha, I 'thought' I was setting up the Beta. Well I am almost finish setting it up, i guess this is the previous script prior to the Beta?
I can wait, though in a couple of hours here it will be Monday, lol. Thank you again for you time and effort.
P.S. I am curious about adding a tab for 'voice-to-text' as I am doing a lot of that lately and not sure if it really counts as writing. Of course the painful editing i have to do afterwards certainly counts.

For what it is worth, here are the error messages i received this morning :

8/10/14 11:51 PM getDailyWordCount ReferenceError: "Sandbox" is not defined. (line 119, file "Code") time-based 8/10/14 11:51 PM
&
8/11/14 1:38 AM getAlamancText Bad value (line 326, file "Code") time-based 8/11/14 1:38 AM
I was thinking that you were going to alert me to the new README but after reading your last message again I see that I need to check your page again, so I will do that now.

After switching to the beta track I also get the "Cannot find method formatDate(string,string,string). (line 512, file "Code")" error. I verified the spreadsheet and script project settings are using the same timezone.

Line 512: var curDate = Utilities.formatDate(data[i][j], TIME_ZONE, "MM/dd/yyyy");

Did you check to make sure both the scripts and the spreadsheet have the
same timezone set? There are instructions for how to check this in the
README.


Jamie Todd Rubin (@jamietr http://twitter.com/jamietr)
http://www.jamietoddrubin.com
http://www.jamietoddrubin.com/going-paperless/

On Tue, Aug 26, 2014 at 2:09 PM, OthelloPrime notifications@github.com
wrote:

After switching to the beta track I also get the "Cannot find method
formatDate(string,string,string). (line 512, file "Code")" error. I
verified the spreadsheet and script project settings are using the same
timezone.

Line 512: var curDate = Utilities.formatDate(data[i][j], TIME_ZONE,
"MM/dd/yyyy");


Reply to this email directly or view it on GitHub
#16 (comment)
.

Yes sir. I read the readme twice before I posted here and made sure the timezones were the same.

I figured it out! I had the config spreadsheet set to test mode. The Daily Almanac script generated the error because there was nothing (such as the date) in the 'Writing' tab for the Daily Almanac script to read.

Ah, good catch.


Jamie Todd Rubin (@jamietr http://twitter.com/jamietr)
http://www.jamietoddrubin.com
http://www.jamietoddrubin.com/going-paperless/

On Tue, Aug 26, 2014 at 2:27 PM, OthelloPrime notifications@github.com
wrote:

Yes sir. I read the readme twice before I posted here and made sure the
timezones were the same. But I figured it out! I had the config spreadsheet
set to test mode. The Daily Almanac script generated the error because
there was nothing (such as the date) in the 'Writing' tab for the Daily
Almanac script to read.


Reply to this email directly or view it on GitHub
#16 (comment)
.

I just came to say I found the solution to:

Cannot find method formatDate(string,string,string).(line 512, file "Code") on DailyAlmanac

@rustuptwist gave the answer here.

As for the timezone, in the 'Writing Stats' code.gs page i see instances of TIME_ZONE '"yyyy-MM-dd" (lines 131, 135, 153) whereas in the the DailyAlmanac code.gs page it isTIME_ZONE "MM/dd/yyyy (line 92). Again since no one is reporting problems I assume it is me.

All I did was change MM/dd/yyyy on all DailyAlmanac instances to yyyy-MM-dd and the problem got solved. I finally got DailyAlmanac working after all this time! So excited.

PS. You do have to check timezones match on Spreadsheet and both Scripts.

I have this error, too. I've not gotten this to work at all and I'm a programmer, so I edit each day, still can't get it to work and then scrap my changes and overwrite the entire thing again with the master file and hope for the best.

I am getting this error on the function getAlamanacText:

Cannot find method formatDate(string,string,string). (line 512, file "Code")

I have looked up everything on this in Google Scripts help and StackOverflow. Here is the specific code line 512 this error is referencing:

var curDate = Utilities.formatDate(data[i][j], TIME_ZONE, "yyyy-MM-dd");

As near as I can tell this is getting the difference between yesterday and today and how much I've written to log it. I have written both days, so there should (in theory) be a difference. But instead of working it errors.

Anyone have any ideas? I would love ot have this working, but I've been trying to make it work every morning for 10 days and can't figure it out.

As I cannot reproduce the issue, I'm not sure the following will be much help.

The reason you are getting the error is because the first parameter (data[i][j]) is a string and not, as required, a date. I see two ways around it:

  1. Open the Google Writing Tracker Data sheet, click on the header of column A, in the menu select: Format > Number > Date (Automatic should also work if data in the sheet is recognized in the correct date format). After this, data[i][j] should be of type date and it should work. If there are currently now rows in the file, you might need to add the first line.

  2. You could try to change line 512 to: Utilities.formatDate(new Date(data[i][j]), TIME_ZONE, "MM/dd/yyyy"); I'm not sure that this will work though.

To debug you can add the following method:

function test() {
var qs_doc = SpreadsheetApp.openById(WRITING_DATA);
var sheet = qs_doc.getSheetByName("Writing");
var data = sheet.getRange("A2:A" + sheet.getLastRow()).getValues();
Logger.log(data[0][0]);
Logger.log(data[0][0] instanceof Date);
}

When you press Ctrl+Enter after executing the test function, it should show something like this:
Thu Aug 13 00:00:00 GMT+02:00 2015
true

If it just shows exactly what is written in the cell (e.g. 02/02/2018) then it's most likely a string. If the second one is "false", then you don't have a date object and it will not work.

Hi, thanks for reply. I did open the spreadsheet and change the date format on the header Column A and things things to work smoothly after that

AND

While I was doing that, I noticed that there were a couple of lines entered in the spreadsheet at the top and then I had tried to update some rows manually and the writing tracker was adding lines below my addition. There was a blank row in there and I remembered reading that there shouldn't be. Once I deleted the blank row and everything moved up, the error went away and everything is tracking, the "Earlier" folder is updating and the program is sending me yesterday's work in an email.

Thank you so much!