-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenVotingKey.js
50 lines (43 loc) · 1.28 KB
/
genVotingKey.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
const PouchDB = require('pouchdb');
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const csvWriter = createCsvWriter({
path: 'votingKeys.csv',
header: [
{id: 'url', title: 'URL'},
]
});
const account = 'be8a3d9c-c44b-431c-9a32-69389efeb85a-bluemix';
const apiKey = 'fintsprockekstructingene';
const apiPassword = '6ac6e4c44eed1df7a43e9351911968f78a29c446';
const baseUrl = `https://${apiKey}:${apiPassword}@${account}.cloudant.com/voting-keys`;
const db = new PouchDB(baseUrl);
const genKey = (length) => {
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let key = '';
for (let i = 0; i < length; i++) {
key += possible[ Math.floor(Math.random() * possible.length) ];
}
return key;
}
let votingKeys = [];
const putDb = async () => {
for (let i = 1; i <= 500; i++) {
const webUrl = 'https://make.ntuee.org/pop-prize/';
const key = genKey(16);
votingKeys.push({
url: webUrl + key
});
await db.put({
_id: key,
key: key
}).then((res) => {
console.log(`key ${i} success`);
}).catch((err) => {
console.log(err);
});
}
};
putDb().then(() => {
csvWriter.writeRecords(votingKeys)
.then(() => console.log('The CSV file was written successfully'));
});