#!/usr/bin/env node /** * Script batch pour compléter les dates manquantes dans hash_list.txt * Ajoute la colonne date (ISO 8601) si elle est absente */ import { readFileSync, writeFileSync, existsSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const hashListPath = join(__dirname, '../hash_list.txt'); if (!existsSync(hashListPath)) { console.error('hash_list.txt not found'); process.exit(1); } try { const content = readFileSync(hashListPath, 'utf8').trim(); if (!content) { console.log('hash_list.txt is empty'); process.exit(0); } const lines = content.split('\n'); const now = new Date().toISOString(); let updated = 0; const outputLines = lines.map((line) => { if (!line.trim()) return line; const parts = line.split(';'); // Format attendu: hash;txid;blockHeight;confirmations;date if (parts.length === 4) { // Ancien format sans date, ajouter date actuelle updated++; return `${line};${now}`; } else if (parts.length === 5) { // Format avec date, vérifier si date valide const date = parts[4]; if (!date || date.trim() === '') { updated++; return `${parts.slice(0, 4).join(';')};${now}`; } return line; } return line; }); if (updated > 0) { writeFileSync(hashListPath, outputLines.join('\n'), 'utf8'); console.log(`✅ ${updated} ligne(s) mise(s) à jour avec date dans hash_list.txt`); } else { console.log('✅ Toutes les lignes ont déjà une date dans hash_list.txt'); } } catch (error) { console.error('Error:', error.message); process.exit(1); }