-
Notifications
You must be signed in to change notification settings - Fork 1
/
images.js
41 lines (34 loc) · 910 Bytes
/
images.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
const download = require("image-downloader");
var fs = require("fs");
function downloadImage(url, filepath) {
return download.image({
url,
dest: filepath,
});
}
function printProgress(progress, total) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(progress + "/" + total);
}
async function main() {
let baseURI = "https://img.chainrunners.xyz/api/v1/tokens/png/";
let projectName = "Runners";
let folderBase = "/extracted";
let projectDir = __dirname + folderBase + "/" + projectName + "/images/";
let size = 13000;
if (!fs.existsSync(projectDir)) {
fs.mkdirSync(projectDir, { recursive: true });
}
for (var i = 1; i < size; i++) {
let file = baseURI + i;
await downloadImage(file, projectDir);
printProgress(i, size);
}
console.log("Download complete");
}
try {
main();
} catch (error) {
console.error(error);
}