Update database connection details and add scripts for image URL updates and downloads
@@ -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();
|
||||
});
|
||||
@@ -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();
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
$servername = "localhost:3306";
|
||||
$username = "database1";
|
||||
$password = "181t$1lJg";
|
||||
$dbname = "pokedex1";
|
||||
$servername = "localhost";
|
||||
$username = "root";
|
||||
$password = "";
|
||||
$dbname = "pokedex";
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 199 KiB |
|
After Width: | Height: | Size: 170 KiB |
|
After Width: | Height: | Size: 178 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 160 KiB |
|
After Width: | Height: | Size: 133 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 143 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 186 KiB |
|
After Width: | Height: | Size: 98 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 166 KiB |
|
After Width: | Height: | Size: 153 KiB |
|
After Width: | Height: | Size: 131 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 183 KiB |
|
After Width: | Height: | Size: 150 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 145 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 150 KiB |
|
After Width: | Height: | Size: 217 KiB |
|
After Width: | Height: | Size: 179 KiB |
|
After Width: | Height: | Size: 138 KiB |
|
After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 102 KiB |
|
After Width: | Height: | Size: 170 KiB |
|
After Width: | Height: | Size: 179 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 194 KiB |
|
After Width: | Height: | Size: 157 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 131 KiB |
|
After Width: | Height: | Size: 155 KiB |
|
After Width: | Height: | Size: 139 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 106 KiB |
|
After Width: | Height: | Size: 143 KiB |
|
After Width: | Height: | Size: 133 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 139 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 139 KiB |
|
After Width: | Height: | Size: 146 KiB |
|
After Width: | Height: | Size: 150 KiB |
|
After Width: | Height: | Size: 170 KiB |
|
After Width: | Height: | Size: 157 KiB |
|
After Width: | Height: | Size: 124 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 133 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 136 KiB |
|
After Width: | Height: | Size: 157 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 129 KiB |
|
After Width: | Height: | Size: 143 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 102 KiB |
|
After Width: | Height: | Size: 87 KiB |
|
After Width: | Height: | Size: 114 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 160 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 129 KiB |
|
After Width: | Height: | Size: 133 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 162 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 155 KiB |
|
After Width: | Height: | Size: 98 KiB |
|
After Width: | Height: | Size: 88 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 148 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 182 KiB |
|
After Width: | Height: | Size: 110 KiB |