Add initial files and configuration for Pokedex project, including SVG icons and VSCode settings

This commit is contained in:
vista-man
2025-03-30 03:22:49 +02:00
parent 8b3d738e50
commit 9acbc04ae1
4106 changed files with 4616 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
const fs = require('fs');
const path = require('path');
const https = require('https');
const mysql = require('mysql');
const { exec } = require('child_process');
const downloadDir = path.join(require('os').homedir(), 'Downloads', 'pokemon-images');
// Create the download directory if it doesn't exist
if (!fs.existsSync(downloadDir)) {
fs.mkdirSync(downloadDir, { recursive: true });
}
// Database connection
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'pokedex',
});
connection.connect();
// Fetch Pokémon data
connection.query('SELECT id, image_url FROM pokemon', (error, results) => {
if (error) throw error;
results.forEach((pokemon) => {
const file = fs.createWriteStream(path.join(downloadDir, `${pokemon.id}.png`));
https.get(pokemon.image_url, (response) => {
response.pipe(file);
file.on('finish', () => {
file.close();
console.log(`Downloaded: ${pokemon.image_url}`);
});
}).on('error', (err) => {
fs.unlink(path.join(downloadDir, `${pokemon.id}.png`));
console.error(`Error downloading ${pokemon.image_url}: ${err.message}`);
});
});
connection.end();
});