Update database connection details and add scripts for image URL updates and downloads

This commit is contained in:
vista-man
2025-03-25 12:29:38 +01:00
parent 326e4da1cb
commit 837d2cc8b5
1013 changed files with 77 additions and 4 deletions

30
update-image-urls.js Normal file
View File

@@ -0,0 +1,30 @@
const mysql = require('mysql');
// Database connection
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'pokedex',
});
connection.connect();
// Fetch Pokémon data
connection.query('SELECT id FROM pokemon', (error, results) => {
if (error) throw error;
results.forEach((pokemon) => {
const newImageUrl = `./images/${pokemon.id}.png`;
connection.query(
'UPDATE pokemon SET image_url = ? WHERE id = ?',
[newImageUrl, pokemon.id],
(updateError) => {
if (updateError) throw updateError;
console.log(`Updated image URL for Pokémon ID: ${pokemon.id}`);
}
);
});
connection.end();
});