From fa37222c75f2f8286c6b2cdb31e516ef37cfd275 Mon Sep 17 00:00:00 2001 From: vista-man <524715@vistacollege.nl> Date: Tue, 25 Mar 2025 17:12:28 +0100 Subject: [PATCH] =?UTF-8?q?Add=20script=20to=20update=20low-resolution=20i?= =?UTF-8?q?mage=20URLs=20in=20Pok=C3=A9mon=20database?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update_low_res_images.js | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 update_low_res_images.js diff --git a/update_low_res_images.js b/update_low_res_images.js new file mode 100644 index 0000000..0ad2497 --- /dev/null +++ b/update_low_res_images.js @@ -0,0 +1,51 @@ +const mysql = require('mysql'); +const fs = require('fs'); +const path = require('path'); + +const connection = mysql.createConnection({ + host: 'localhost', + user: 'database1', + password: '181t$1lJg', + database: 'pokedex1' +}); + +connection.connect((err) => { + if (err) { + console.error('Error connecting to the database:', err); + return; + } + console.log('Connected to the database.'); + updateLowResImages(); +}); + +function updateLowResImages() { + const imagesDir = path.join(__dirname, 'small-images'); + fs.readdir(imagesDir, (err, files) => { + if (err) { + console.error('Error reading the images directory:', err); + return; + } + + files.forEach((file) => { + const id = path.parse(file).name; + const imageUrlLow = `/small-images/${file}`; + const query = 'UPDATE pokemon SET image_url_low = ? WHERE id = ?'; + + connection.query(query, [imageUrlLow, id], (err, result) => { + if (err) { + console.error(`Error updating image_url_low for Pokémon ID ${id}:`, err); + return; + } + console.log(`Updated image_url_low for Pokémon ID ${id}`); + }); + }); + + connection.end((err) => { + if (err) { + console.error('Error closing the database connection:', err); + return; + } + console.log('Database connection closed.'); + }); + }); +}