forked from austintgriffith/paper-wallet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbatch-stickers-templ.js
52 lines (46 loc) · 1.55 KB
/
batch-stickers-templ.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
const { generateWallet, generateStickers } = require('./helpers');
const util = require('util');
const asyncStickers = util.promisify(generateStickers);
var merge = require('easy-pdf-merge');
var fs = require('fs');
const URL = "https://sundai.io"
const HOWMANY = 100;
const PATH = 'wallets';
const BATCH = 'extra';
const workDir = process.cwd();
const perPage = 12;
async function generate() {
let accounts = [];
let sources = [];
const pages = Math.ceil(HOWMANY / perPage);
for (let i = 0; i < HOWMANY; i++) {
accounts.push(generateWallet(URL, `./${PATH}`,BATCH));
}
let pageAccounts;
let name;
console.log('--------------');
console.log(accounts);
for (let i = 0; i < pages; i++) {
pageAccounts = accounts.slice(i * perPage, (i + 1) * perPage);
console.log('--------------');
console.log(pageAccounts);
name = `Batch-${BATCH}_${pageAccounts[0].substring(0,8)}`;
await asyncStickers(pageAccounts, workDir + '/' + PATH, name, perPage);
console.log("Generated: " + name);
sources[i] = (""+PATH+"/"+name+".pdf");
}
while(!fs.existsSync(sources[pages-1])) {
//console.log('.');
}
merge(sources,PATH + "/wallets-" + BATCH + ".pdf",function(err){
if(err)
return console.log(err);
console.log('Success');
var i = sources.length;
sources.forEach(function(filepath){
console.log("Cleaning up "+filepath)
fs.unlinkSync(filepath);
});
});
}
generate();