mirror of
https://github.com/chase-manning/pokemon-js.git
synced 2025-08-26 03:07:14 +00:00
✨ add script to download images
This commit is contained in:
parent
de3fdffb74
commit
828fea32aa
1 changed files with 21 additions and 0 deletions
21
scripts/download-images.js
Normal file
21
scripts/download-images.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
const fs = require("fs");
|
||||||
|
const fetch = require("node-fetch");
|
||||||
|
|
||||||
|
const pokemon = JSON.parse(fs.readFileSync("data.json"));
|
||||||
|
|
||||||
|
const downloadData = async () => {
|
||||||
|
for (let i = 1; i < 152; i++) {
|
||||||
|
const poke = pokemon[i];
|
||||||
|
const front = poke.images.front;
|
||||||
|
const back = poke.images.back;
|
||||||
|
const frontResponse = await fetch(front);
|
||||||
|
const backResponse = await fetch(back);
|
||||||
|
const frontBuffer = await frontResponse.buffer();
|
||||||
|
const backBuffer = await backResponse.buffer();
|
||||||
|
fs.writeFileSync(`./images/front/${i}.png`, frontBuffer);
|
||||||
|
fs.writeFileSync(`./images/back/${i}.png`, backBuffer);
|
||||||
|
console.log(`Downloaded ${poke.name}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
downloadData();
|
Loading…
Add table
Add a link
Reference in a new issue