-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEventSeeder.js.save
67 lines (56 loc) · 1.76 KB
/
EventSeeder.js.save
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
//INSTALL : npm install google-spreadsheet
const GoogleSpreadsheet = require('google-spreadsheet');
const {promisify}=require('util');
var mongoose=require('mongoose'),
LocalUser = require('./models/LocalUser.js');
GoogleUser = require('./models/GoogleUser.js');
//CONNECTION
mongoose.connect("mongodb://localhost:27017/tirutsava2020", {useNewUrlParser: true, useCreateIndex: true})
.then(() => console.log('Database is Connected...'))
.catch((err) => console.log(err));
const creds = require('./client_secret.json');
//FAQs Part.
function printQuery(event){
console.log(event); //For Debugging purpose
}
async function accessSpreadsheet(){
const doc = new GoogleSpreadsheet('1sdOntCOMEJPGmdDKycHOBaC_-kqRyOQS6vkahJQKFAw');
await promisify(doc.useServiceAccountAuth)(creds);
const info = await promisify(doc.getInfo)()
console.log(info.worksheets.length);
var sheet=info.worksheets[0];
await doc.removeWorksheet(sheet);
sheet = await doc.addWorkshee const rows = await promisify(sheet.getRows)({
offset:1
});
rows.forEach(async row =>{
// console.log(row);
// printFAQ(row);
//await row.del();
});
//DELETING OLDER ENTRIES, BEFORE WRITING AFRESH.
for(var i=0;i<rows.length;i++){
if(rows[i])
await rows[i].del();
}
//CREATING A NEW ROW:
LocalUser.find({registeredeventids: 25},async function(err, users){
users.forEach(async (user) =>{
var row={
Name: user.name,
Mail: user.email
};
await promisify(sheet.addRow)(row);
});
});
GoogleUser.find({registeredeventids: 25},async function(err, users){
users.forEach(async (user) =>{
var row={
Name: user.name,
Mail: user.email
};
await promisify(sheet.addRow)(row);
});
});
}
accessSpreadsheet();