-
Notifications
You must be signed in to change notification settings - Fork 1
/
getArtwork.js
31 lines (22 loc) · 922 Bytes
/
getArtwork.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
import fs from "fs/promises"
import fetch from 'node-fetch'
import path from "path"
const fetchArtwork = async (name) => {
const namePokemon = name
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${namePokemon}`)
const json = await response.json()
// retreving the stats for the character
const spritesObject = json.sprites
console.log()
for(const key in spritesObject) {
if(key === 'other') {
const officialArt = spritesObject.other['official-artwork']['front_default']
const officialImage = await fetch(officialArt)
const arrayBuffer = await officialImage.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
const createArtwork = await fs.appendFile(`./${namePokemon}/${key}.png`, buffer, "binary")
console.log(`Saved: ${namePokemon}/${key}.png`)
}
}
}
export { fetchArtwork }