This is a Google Apps Script for creating the tree structure from headings in Google Documents.
| /* | |
| * Copyright 2017 Mohsen Mesgarpour | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software |
This is a sample script for creating Google Document by converting PDF and image files with OCR using Google Apps Script.
Before you run this sample script, please install a GAS library of FetchApp.
function sample() {
var fileId = "### fileId of PDF file and image files ###";
var metadata = {This is a sample script for efficiently creating Web Apps using a Google Apps Script library.
When a Google Apps Script library is used for creating Web Apps, the following advantage can be obtained.
- The script of the client-side can be simpler. Because most scripts for constructing Web Apps are included in the Google Apps Script library.
- When the script of Web Apps (In this case, the script of Google Apps Script library is modified.) is modified, the latest script is reflected in the Web Apps, immediately. Because when the Google Apps Script library is used as the latest version when the script of the library is modified, the client can use the latest script of the library, immediately. So, the downtime of Web Apps can be reduced.
- By this, it is not required to manually reflect the latest version of the script to the Web Apps.
- When you can change the script of Web Apps by changing the deployed version of the library.
This is a sample script for converting a lot of files to Google Docs (Spreadsheet, Document and Slides).
- Batch request can be used for converting files. In this sample script, the files are converted using the batch request.
- Batch request can request 100 API by one API call.
- This sample script uses the fetchAll method. So even if there are over 100 files, this script can process them.
Before you run the script, please set the variables at main(). And, please enable Drive API at Advanced Google services.
| // @OnlyCurrentDoc | |
| const FOLDER_ID = 'YOUR_FOLDER_ID'; // OR 'root' if you want your entire My Drive | |
| /** | |
| * Method One: Using built-in DriveApp / file iterator | |
| */ | |
| function generateFolderFilesDriveApp() { | |
| try { | |
| const folderId = FOLDER_ID; | |
| const parentFolder = (folderId === 'root') ? DriveApp.getRootFolder() : DriveApp.getFolderById(folderId); |
At October 11, 2019, I published a Javascript library to to run the resumable upload for Google Drive. When this is used, the large file can be uploaded. You can also use this js library.
This is a sample script for uploading files to Google Drive using Javascript. The files are uploaded by Drive API v3. gapi.client.drive.files.create() can create an empty file on Google Drive. But it cannot directly upload files including contents. I think that this might not be able to upload files and metadata with the multipart/related, although this might be resolved by the future update. So now, as one of workarounds, I use using XMLHttpRequest.
- This sample uses gapi.
- Before you use this, please enable Drive API at API console and carr
| function combineData(){ | |
| var doc = SpreadsheetApp.getActiveSpreadsheet(); | |
| var sheets = doc.getSheets(); // get all the sheets | |
| var outSheet = doc.getSheetByName("combined"); // set where we want to write the results | |
| for (i in sheets){ // loop across all the sheets | |
| if (sheets[i].getSheetName().substring(0,9) == "followers"){ // if sheetname starts with 'follower' then | |
| var target = sheets[i].getSheetName().substring(12); // extract users name for target column | |
| var data = getRowsData(sheets[i]); // get extisting data from current sheet | |
| for (j in data){ | |
| data[j]["target"] = target; // create a target column with the users name |
A Versatile Approach to Uploading Files with Node.js: Integrating Gemini, Drive, YouTube, and Other APIs
A script using resumable upload with file streams is proposed to enhance file handling within the Gemini Generative AI API for Node.js. This script allows uploading from web URLs and local storage, efficiently handles large files, and offers potential reusability with other Google APIs.
The @google/generative-ai library provides a powerful way to interact with the Gemini Generative AI API using Node.js. This enables developers to programmatically generate creative text formats, translate languages, write different kinds of creative content, and answer your questions in an informative way, all powered by Gemini's advanced AI models. Ref
This report presents a method to optimize AI-generated scripts for processing costs using Gemini and Google Apps Script. By incorporating external knowledge from sources like StackOverflow, we demonstrate the effective generation of efficient scripts that minimize overhead while maintaining desired outcomes. This approach can be considered a dynamic pseudo-RAG technique.
The proliferation of generative AI, exemplified by Google Gemini, has led to a surge in AI-generated scripts. This trend is evident in the growing number of questions on platforms like StackOverflow that involve AI-generated scripts. While this indicates a significant improvement in AI performance, it's crucial to note that AI-generated scripts may not always be optimized for processing costs, especially when the prompt fails to provide sufficient context.
