ggsrun was updated to v.1.4.1
- v1.4.1 (February 9, 2018)
- For uploading, the resumable-upload method was added.
- The resumable-upload method is automatically used by the size of file.
- “multipart/form-data” can upload files with the size less than 5 MB.
- “resumable-upload” can upload files with the size more than 5 MB.
- The chunk for resumable-upload is 100 MB as the default.
- Users can also give this chunk size using an option.
$ ggsrun u -f filename -chunk 10
- This means that a file with filename is uploaded by each chunk of 10 MB.
You can read “How to install” at here.
Gists
This is a sample script for copying values from JSON to a struct using reflect package.
Script :
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type obj struct {
Key1 string `json:"k1"`
Key2 string `json:"k2"`
Key3 int64 `json:"k3"`
Key4 int `json:"k4"`
Key5 bool `json:"k5"`
}
func main() {
data := `{"k1": "v1", "k2": "v2", "k3": 1234567890, "k4": 456, "k5": true}`
d := map[string]interface{}{}
json.Unmarshal([]byte(data), &d)
obj := &obj{}
s := reflect.ValueOf(obj).Elem()
typeOfT := s.Type()
for i := 0; i < s.NumField(); i++ {
for j, f := range d {
if typeOfT.Field(i).Tag.Get("json") == j {
fl := s.FieldByName(typeOfT.Field(i).Name)
switch fl.Kind() {
case reflect.Bool:
fl.SetBool(f.(bool))
case reflect.Int, reflect.Int64:
c, _ := f.(float64)
fl.SetInt(int64(c))
case reflect.String:
fl.SetString(f.(string))
}
}
}
}
fmt.Printf("%+v\n", obj) // &{Key1:v1 Key2:v2 Key3:1234567890 Key4:456 Key5:true}
}
Result :
&{Key1:v1 Key2:v2 Key3:1234567890 Key4:456 Key5:true}
The Go Playground
https://play.golang.org/p/Rz-GNbFyDfh
Gists
This sample script is for parsing JSON object. In the object, the keys are number and changing every time.
Object:
{
"key1": {
"key2": [
{"0": [{"key3": "value3a"}, {"key3": "value3b"}]},
{"1": [{"key3": "value3c"}, {"key3": "value3d"}]}
]
}
}
Script:
package main
import (
"encoding/json"
"fmt"
"strconv"
)
type key1 struct {
Key1 key2 `json:"key1"`
}
type key2 struct {
Key2 []interface{} `json:"key2"`
}
func main() {
data := `{"key1": {"key2": [{"0": [{"key3": "value3a"}, {"key3": "value3b"}]},{"1": [{"key3": "value3c"}, {"key3": "value3d"}]}]}}`
k1 := &key1{}
json.Unmarshal([]byte(data), &k1)
for i, e := range k1.Key1.Key2 {
if key, ok := e.(map[string]interface{})[strconv.Itoa(i)].([]interface{}); ok {
for _, f := range key {
fmt.Printf("%+v\n", f.(map[string]interface{})["key3"])
}
}
}
}
Result:
value3a
value3b
value3c
value3d
The Go Playground
https://play.golang.org/p/xm2KvgOIkKH
Gists
These are sample scripts for adding a label to a message using message ID for Gmail.
Sample 1
This sample adds a label to a thread using message ID. In this case, all messages in the thread have the label. Even if it adds a label to a message in the thread using addLabel(), all messages in the thread have the label, becauce addLabel can only be used for the thread.
Gists
Description :
This sample script is for retrieving emails which replied for received mails. Because there are no samples which confirm whether the owner (me) replied to the received mails, I created this. The point is as follows.
- When there are more than 2 messages in a thread, there might be a possibility to have replied.
- For more than 2 messages in a thread
- The email address of “from” for the 1st message is the sender’s address.
- When the email address of “to” of after 2nd messages is the same to that of “from” of 1st one, it is indicates that the thread was replied by owner.
This sample script is made of Google Apps Script (GAS). But also this can be applied to other languages.
ManifestsApp was updated to v1.0.2.
You can check this at https://github.com/tanaikech/ManifestsApp.
Overview
This is a GAS project library for Google Apps Script (GAS). This library can be used for the projects of both standalone script type and container-bound script type.
Description
There are Class SpreadsheetApp and Class DocumentApp for operating spreadsheet and document, respectively. But there is no Class for operating GAS project. If there is such Class ProjectApp, GAS project can be directly operated by GAS script. I thought that this will lead to new applications, and created ProjectApp. On the other hand, as a CLI tool for operating GAS project, there has already been ggsrun.
google.script.run doesn’t return values. So I tried this using jQuery.Deferred.
GAS : Code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile('index')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function getValues(e) {
return e + "hoge";
}
HTML : index.html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.js"></script>
<body>
<input type="button" id="button" value="ok">
<div id="result"></div>
<script>
$(() => {
$("#button").click(() => {
var str = "fuga";
googleScriptRun(str).then((res) => {
$('#result').text(res);
});
});
});
function googleScriptRun(str) {
var d = new $.Deferred();
google.script.run.withSuccessHandler((res) => {d.resolve(res)}).getValues(str);
return d.promise();
}
</script>
</body>
Result :
fugahoge
Above sample can be also written as follows.
ggsrun was updated to v.1.4.0
-
v1.4.0 (January 25, 2018)
Google Apps Script API was finally released. From this version, ggsrun uses this API. So ggsrun got to be able to use not only projects of standalone script type, but also projects of container-bound script type. I hope this updated ggsrun will be useful for you.
- To users which are using ggsrun with v1.3.4 and/or less.
- For retrieving, downloading, creating and updating projects, Apps Script API is used.
- About retrieving information of projects, the information from Drive API is more than that from Apps Script API. So I used Drive API in this situation.
- Please read how to enable APIs.
- ggsrun got to be able to use both standalone scripts and container-bound scripts by Apps Script API.
- Create projects
- Update projects
- There are some issues for creating projects.
- After Manifests was added to GAS, the time zone can be set by it. But when a new project is created by API, I noticed that the time zone is different from own local time zone. When a new project is manually created by browser, the time zone is the same to own local time zone. I think that this may be a bug. So I added an option for setting time zone when a new project is created. And also I reported about this to Google Issue Tracker.
- If you want to create a bound script in Slide, an error occurs. When a bound script can be created to Spreadsheet, Document and Form using Apps Script API. Furthermore, when the bound script in Slide is updated, it works fine. So I think that this may be also a bug. I reported about this to Google Issue Tracker.
- About this, when you create a bound script in Slides, if ggsrun returns no errors, it means that this issue was solved.
- Both standalone scripts and container-bound scripts can be rearranged.
- The file of
appsscript for Manifests is always displayed to the top of files on the script editor, while the array of files can be changed. I think that this is the specification.
- For the option
exe1 for executing GAS, it can use for both standalone scripts and container-bound scripts.
- Delete files using file ID on Google Drive.
- Delete files in the project.
- ggsrun can create new container-bound script in the new Google Docs.
- For example, ggsrun creates a new Spreadsheet and uploads the script files to the Spreadsheet as a container-bound script.
- Retrieve and create versions of projects.
- Unified the order of directories for searching
client_secret.json and ggsrun.cfg.
- Some modifications.
You can read “How to install” at here.