-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
120 lines (107 loc) · 2.75 KB
/
test.js
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const {
getAuthToken,
getSpreadSheet,
getSpreadSheetValues,
addValuesSpreadSheet,
updateValuesSpreadSheet,
updateRangeValuesSpreadSheet,
} = require("./googleSheetsService.js");
require("dotenv").config();
const spreadsheetId = process.env.SPREADSHEETID;
const sheetName = process.env.SHEETNAME;
const values = ["John", "Doe", "example@example.com"];
async function testGetSpreadSheet() {
try {
const auth = await getAuthToken();
const response = await getSpreadSheet({
spreadsheetId,
auth,
});
console.log(
"output for getSpreadSheet",
JSON.stringify(response.data, null, 2)
);
} catch (error) {
console.log(error.message, error.stack);
}
}
async function testGetSpreadSheetValues() {
try {
const auth = await getAuthToken();
const response = await getSpreadSheetValues({
spreadsheetId,
sheetName,
auth,
});
// console.log(JSON.stringify(response.data.values, null, 2));
return response.data.values;
} catch (error) {
// console.log(error.message, error.stack);
return error.message;
}
}
async function testAddValuesSpreadSheet() {
try {
const auth = await getAuthToken();
const response = await addValuesSpreadSheet({
spreadsheetId,
sheetName,
auth,
values,
});
console.log(
"output for addValuesSpreadSheet",
JSON.stringify(response.data, null, 2)
);
} catch (error) {
console.log(error.message, error.stack);
}
}
async function updateSpreadsheet(row, column, value) {
try {
// Get the authentication token
const auth = await getAuthToken();
// Update the value in the spreadsheet
const response = await updateValuesSpreadSheet({
spreadsheetId,
auth,
sheetName,
row,
column,
value,
});
console.log("Value updated successfully:", response.data);
} catch (error) {
console.error("Error updating value:", error);
}
}
async function updateRangeSpreadsheet(range, values) {
try {
// Get authentication token
const auth = await getAuthToken();
// Range and values to update
// const range = "B2:F2";
// const values = ["Value1", "Value2", "Value3", "Value4", "Value5"];
// Update the range with the values
const response = await updateRangeValuesSpreadSheet({
spreadsheetId,
auth,
sheetName,
range,
values,
});
console.log("Range updated successfully:", response.data);
} catch (error) {
console.error("Error updating range:", error);
}
}
async function main() {
const data = await testGetSpreadSheetValues();
const urls = data.slice(1).map((el) => {
return el[0];
});
console.log(urls);
// updateSpreadsheet(2, 'K', 1888);
// testAddValuesSpreadSheet();
}
main();