-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_spreadsheet
executable file
·101 lines (87 loc) · 2.16 KB
/
google_spreadsheet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
# Google Oauth 2 for bash
# Copyright (C) 2018 Samuel Rodriguez Sevilla <[email protected]>
# Copyright (C) 2018 Distribuidira Internacional de Alimentacion S.A.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# This should be eliminated from here
. google_oauth2
function cellValue() {
cat <<END
{
"userEnteredValue": {
"$1Value": "$2"
}
}
END
}
function appendCells() {
local sheetId="$1"
local rows=""
local row=""
shift
while [ -n "$1" ]; do
case "$1" in
row)
if [ -n "$rows" ]; then
rows="$rows, {\"values\": [$row]}"
elif [ -n "$row" ]; then
rows="{\"values\": [$row]}"
fi
row=
;;
*)
local type="${1/:*/}"
local value="${1/*:/}"
local cellData="$(cellValue "${type}" "${value}")"
if [ -z "$row" ]; then
row="${cellData}"
else
row="$row, ${cellData}"
fi
;;
esac
shift
done
if [ -n "$rows" ]; then
rows="$rows, {\"values\": [$row]}"
else
rows="{\"values\": [$row]}"
fi
cat <<END
{
"appendCells": {
"sheetId": ${sheetId},
"rows": [$rows],
"fields": "*"
}
}
END
}
function batchUpdate() {
local spreadsheet="$1"
local URL="https://sheets.googleapis.com/v4/spreadsheets/${spreadsheet}:batchUpdate"
shift
local data=
while [ -n "$1" ]; do
if [ -z "${data}" ];then
data="$1"
else
data="$data,$1"
fi
shift
done
data="{ \"requests\": [$data], \"includeSpreadsheetInResponse\": false, \"responseIncludeGridData\": false }"
curl ${PROXY} -H "Content-Type: application/json" -H "Authorization: ${token_type} ${access_token}" "${URL}" --data "${data}"
}