This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
getdata.js
82 lines (77 loc) · 2.06 KB
/
getdata.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
// tut here: https://sprintworks.se/blog/data-from-google-drive-in-static-websites/
import GoogleSpreadsheet from "google-spreadsheet";
import async from "async";
import fs from "fs";
const doc = new GoogleSpreadsheet(
// Using our example spreadsheet: https://docs.google.com/spreadsheets/d/1o_NWrDsVNSVU1jViexKQi08aI6h76fXrMIcvbT9faoM/edit#gid=0
"1sGXCAVauVfeBdy3d0Jp_RHwbntCeTQI8Lsw1k4GqFPY"
);
let sheet;
async.series([function setAuth(step) {
const creds = require("./magicgreen-ab82b0150ffc.json");
doc.useServiceAccountAuth(creds, step);
}, function getInfoAndWorksheets(step) {
doc.getInfo((err, info) => {
console.log(
"Loaded spreadsheet: " + info.title + " by " + info.author.email
);
// Using the first sheet
sheet = info.worksheets[0];
console.log(
"sheet 1: " + sheet.title + " " + sheet.rowCount + "x" + sheet.colCount
);
step();
});
}, function getStuff(step) {
sheet.getRows(
{
offset: 1,
limit: 100,
orderby: "col1"
}, function(err, rows) {
console.log("Read " + rows.length + " rows");
// Clean companies.yml
fs.truncate("./_data/companies.yml", 0, () => {
});
// Save rows as items in the YAML file
for (let row of rows) {
fs.appendFile(
"./_data/companies.yml",
"- brand: " +
row.brand +
"\n\x20\x20" +
"products: " +
row.products +
"\n\x20\x20" +
"company: " +
row.company +
"\n\x20\x20" +
"website: " +
row.website +
"\n\x20\x20" +
"ig: " +
row.instagram +
"\n\x20\x20" +
"email: " +
row.email +
"\n\x20\x20" +
"telephone: " +
row.telephone +
"\n\x20\x20" +
"address: " +
row.address +
"\n\x20\x20" +
"location: " +
row.location +
"\n\x20\x20" +
"country: " +
row.country +
"\n\n",
err => {
}
);
}
}
);
}
]);