Overcoming execution time limits issue for BlogBooksMaker GAS program by creating linked (not embedded) pictures output doc, Test Version
This post provides some info. about an interesting possibility of using MimeType.HTML instead of MimeType.GOOGLE_DOCS to get linked pictures output document in BlogBooksMaker GAS program which does not trip up on GAS (Google Apps Script) execution time limits. MimeType.GOOGLE_DOCS creates a Google Document with embedded pictures. This makes the output document a large one and it also takes a long time for the document to get written. I think that's when, at times, GAS gives an error which perhaps is due to some execution time limit(s) being reached. In contrast, MimeType.HTML does not embed pictures in the output file but has only links to the pictures. That makes the output document size small and it gets written quickly which, so far in my tests, has successfully completed in GAS without reporting any error. I think these programs complete within GAS execution time limits (for free usage users like me).
For more about BlogBooksMaker program, please visit: BlogBooksMaker Google Apps Script to Create Blogger Blog Book (or Book parts): Description and Stable Version Info, https://ravisiyermisc.blogspot.com/2023/07/blogbooksmaker-google-apps-script-to.html .
The related code change:
// Ref: https://developers.google.com/apps-script/reference/base/mime-type
booktitle += ".html"; // Needs it as otherwise document type gets messed up in Google Drive and
// on Windows when downloaded which has to be fixed with manual change of
// doc type to .html
var Dx = Drive.Files.insert(
{ title: booktitle,
mimeType: MimeType.HTML },
ablob);
//var AssetGDocId = Dx.id;
Logger.log('Wrote "%s" to HTML file:', booktitle );
/*
var Dx = Drive.Files.insert(
{ title: booktitle,
mimeType: MimeType.GOOGLE_DOCS },
ablob);
var AssetGDocId = Dx.id;
Logger.log('Wrote "%s" to GDoc.', booktitle );
*/
--- end related code change ---
For producing an embedded pictures version of these output document(s), I can download them to my PC and then use Microsoft Word (on PC) to first convert the HTML to a Word document (.docx). Then I can change all linked pictures in the Word document to embedded pictures by using the VBA macro ChangeLinkedImageToEmbedded() that is covered in my blog post: Word VBA to make Blog Feed into Word document or Book, Test version, https://ravisiyermisc.blogspot.com/2023/07/word-vba-to-make-blog-feed-into-word.html . Eventually from this Word document, I can make a PDF doc with embedded pictures (which is my end goal doc(s) for such work).
Here's the code from my Run-Driver.gs that works with linked pics MimeType.HTML (in Code.gs) followed by same code which had failed some days back (perhaps due to execution time limits) for MimeType.GOOGLE_DOCS (in Code.gs) :
// EklavyaSai (Indian CS & IT Academic Reform past activism) blog is a medium sized one and so all of it
// can go into blog book(s) in one run.
function makeMyEklavyaSaiBlogBooks() {
// 16 Jul. 2023: Trying now with output being HTML (and so with only linked pics and so small size)
// Worked!!! Output file size for all 216 posts (file need to be checked properly): 1,954 KB
funcReturnMsg = makeBlogBooks(null, null, null, null,
"https://www.blogger.com/feeds/8377239296413777485/posts/default?max-results=500&alt=json",
"eklavyasai.blogspot.com");
Logger.log(funcReturnMsg);
....
// Trying out using blog ID instead of blogurl ....
// 13 Jul. 2023: Trying all 216 published posts in one book part run, using fetchurlmainpart parameter
// Tried twice but both times run seems to have got the 215 posts data but finally failed with error:
// 6:39:53 PM Info Error is GoogleJsonResponseException: API call to drive.files.insert failed with error: Bad Request
// 6:39:53 PM Info Failure to write output Google Docs file. Error Message: GoogleJsonResponseException: API call to drive.files.insert failed with error: Bad Request
// So looks like 216 posts data is tripping up Google Drive for free users/usage.
//
/* funcReturnMsg = makeBlogBooks(null, null, null, null,
"https://www.blogger.com/feeds/8377239296413777485/posts/default?max-results=500&alt=json",
"eklavyasai.blogspot.com");
Logger.log(funcReturnMsg); */
--- end code --
Shared Links for Code and Data
This test version is v15.
The top-level share folder for BlogBooksMaker: https://drive.google.com/drive/folders/1jipFEeigwZ4W_LBtEF_jiWZXzFY41Xcs?usp=drive_link
There are two code files for the project:
- Code.gs - Share filename v15Code.gs.txt, https://drive.google.com/file/d/1P5qxuOFSdjmkl4OEhlHYt8SxqmdKAk54/view?usp=drive_link
- Run-Driver.gs - Share filename v15Run-Driver.gs.txt, https://drive.google.com/file/d/1tTVjYjBYVvOGHeBlcbYI-NvNRTZ21_nn/view?usp=drive_link
Two (main) test runs were made and the above code was modified slightly between the two runs but I believe that the changes would not impact the first of the two runs. In other words, I believe that if the above code is run again for the first test, the same or very, very similar output data will be created.
The first run corresponds to the above code extracts. The output blog book had all 216 published posts of eklavyasai.blogspot.com. In the past, using earlier versions of BlogBooksMaker code, such an attempt had failed.
The first run's test data folder, v15Data/Run1 share link: https://drive.google.com/drive/folders/1dbqazV365zYorly0M3YobU_xcIcx283O?usp=drive_link .
The first run's Run Info. and Execution Log (part of above folder), RunInfo-ExecLog.txt share link: https://drive.google.com/file/d/172oS45vns_jebNYzPw-oCqNeW-OeWPly/view?usp=drive_link .
The second run created 150 posts set (8) of my Worldly blog - ravisiyermisc.blogspot.com. With the previous version of the code, it had failed for the 1st set of 150 posts itself (when embedded pics doc was being created).
The second run's test data folder, v15Data/Run2 share link: https://drive.google.com/drive/folders/1uDnEWYDoDIsjIbw82Hh4opEaYmxj2Exp?usp=drive_link .
The second run's Run Info. and Execution Log (part of above folder), RunInfo-ExecLog.txt share link: https://drive.google.com/file/d/1SmLG4r4B4PXRyNlWuwCPcdwLzqR7d1Vy/view?usp=drive_link .
Overall the above two runs involving blog book creation as HTML followed by later process to create Blog Book PDF file with embedded images, page number and Table of Contents, showed that this approach is good. I plan to convert this test approach to a stable solution. Don't know when I will be able to finish that work as I have to get into some other activities. Hopefully it should still get done in the near future.
This test post provides the key facets of the approach I have used. Interested readers are absolutely welcome to use it for their own needs.
Comments
Post a Comment