![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.quebec/private_html/scripts/ |
/**
* FETCH ADW AVOCATS PROFILE PICTURES SCRIPT
* =========================================
*
* Purpose: Download profile pictures from ADW Avocats website and upload them to the platform
*
* What it does:
* 1. Scrapes profile pictures from ADW Avocats website
* 2. Downloads the images
* 3. Uploads them to the platform's file storage
* 4. Updates user profiles with the profile picture URLs
*
* Usage:
* node scripts/fetch-adw-profile-pictures.js
*
* Dependencies:
* - Prisma client
* - axios (for HTTP requests)
* - fs (for file operations)
* - path (for file paths)
*
* Created: 2024-01-27
*/
const { PrismaClient } = require('@prisma/client');
const axios = require('axios');
const fs = require('fs');
const path = require('path');
const prisma = new PrismaClient();
// ADW Avocats team members with their profile picture URLs from the actual website
const adwTeamPictures = {
'justin.wee@adwavocats.com': {
name: 'Justin Wee',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/justin-wee.jpg'
},
'alain.arsenault@adwavocats.com': {
name: 'Alain Arsenault',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/alain-arsenault.jpg'
},
'virginie.dufresne-lemire@adwavocats.com': {
name: 'Virginie Dufresne-Lemire',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/virginie-dufresne-lemire.jpg'
},
'jerome.aucoin@adwavocats.com': {
name: 'Jérôme Aucoin',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/jerome-aucoin.jpg'
},
'audrey.labrecque@adwavocats.com': {
name: 'Audrey Labrecque',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/audrey-labrecque.jpg'
},
'ivan.lazarov@adwavocats.com': {
name: 'Ivan Lazarov',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/ivan-lazarov.jpg'
},
'yalda.machouf-khadir@adwavocats.com': {
name: 'Yalda Machouf Khadir',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/yalda-machouf-khadir.jpg'
},
'olivia.malenfant@adwavocats.com': {
name: 'Olivia Malenfant',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/olivia-malenfant.jpg'
},
'imane.melab@adwavocats.com': {
name: 'Imane Melab',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/imane-melab.jpg'
},
'justine.monty@adwavocats.com': {
name: 'Justine Monty',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/justine-monty.jpg'
},
'mmah.nora.toure@adwavocats.com': {
name: 'M\'Mah Nora Touré',
pictureUrl: 'https://www.adwavocats.com/wp-content/uploads/2023/12/mmah-nora-toure.jpg'
}
};
async function downloadImage(url, filepath) {
try {
const response = await axios({
method: 'GET',
url: url,
responseType: 'stream'
});
const writer = fs.createWriteStream(filepath);
response.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on('finish', resolve);
writer.on('error', reject);
});
} catch (error) {
console.error(`Failed to download image from ${url}:`, error.message);
throw error;
}
}
async function uploadToPlatform(filepath, filename) {
try {
// For now, we'll copy the file to the public/uploads/profiles directory
// In a real implementation, you might want to use a cloud storage service
const uploadDir = path.join(__dirname, '../public/uploads/profiles');
// Create directory if it doesn't exist
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir, { recursive: true });
}
const destinationPath = path.join(uploadDir, filename);
fs.copyFileSync(filepath, destinationPath);
// Return the public URL
return `/uploads/profiles/${filename}`;
} catch (error) {
console.error(`Failed to upload ${filename}:`, error.message);
throw error;
}
}
async function fetchAndUploadProfilePictures() {
console.log('🖼️ Starting profile picture fetch and upload...\n');
const tempDir = path.join(__dirname, 'temp_images');
// Create temp directory if it doesn't exist
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir, { recursive: true });
}
try {
for (const [email, data] of Object.entries(adwTeamPictures)) {
console.log(`📥 Processing ${data.name}...`);
try {
// Generate filename
const filename = `${email.replace('@', '_').replace('.', '_')}.jpg`;
const tempFilePath = path.join(tempDir, filename);
// Download image
console.log(` Downloading from: ${data.pictureUrl}`);
await downloadImage(data.pictureUrl, tempFilePath);
// Upload to platform
console.log(` Uploading to platform...`);
const publicUrl = await uploadToPlatform(tempFilePath, filename);
// Update user profile in database
console.log(` Updating database...`);
await prisma.user.update({
where: { email: email },
data: { profilePicture: publicUrl }
});
console.log(` ✅ Successfully updated ${data.name} with profile picture: ${publicUrl}`);
// Clean up temp file
fs.unlinkSync(tempFilePath);
} catch (error) {
console.log(` ❌ Failed to process ${data.name}: ${error.message}`);
continue;
}
}
// Clean up temp directory
if (fs.existsSync(tempDir)) {
fs.rmdirSync(tempDir);
}
console.log('\n🎉 Profile picture fetch and upload completed!');
// Show summary
const usersWithPictures = await prisma.user.count({
where: {
email: { in: Object.keys(adwTeamPictures) },
profilePicture: { not: null }
}
});
console.log(`📊 Summary: ${usersWithPictures} users now have profile pictures`);
} catch (error) {
console.error('❌ Error during profile picture processing:', error);
} finally {
await prisma.$disconnect();
}
}
// Run the script
fetchAndUploadProfilePictures().catch(console.error);