Files
worst-scan-web/scripts/clean_junk.js
T

19 lines
1.1 KiB
JavaScript

const Database = require("better-sqlite3");
const db = new Database("./data/worst-scan.db");
// Limpiar traducciones basura (las que repiten el prompt)
const junkPrefixes = ["The user wants", "The task", "I need to", "claro que", "esta es una traducción", "aquí tienes", "la traducción es", "por supuesto", "The translation", "Here is", "The title", "Sure", "Voy a traducir", "The user asked"];
const rows = db.prepare("SELECT id, title, title_es FROM posts WHERE title_es IS NOT NULL AND title_es != ''").all();
let cleaned = 0;
for (const r of rows) {
const es = String(r.title_es || "");
const isJunk = junkPrefixes.some((j) => es.startsWith(j)) || es.length > 120;
if (isJunk) {
db.prepare("UPDATE posts SET title_es = NULL WHERE id = ?").run(r.id);
console.log(`limpiado: "${String(r.title).slice(0, 40)}" -> era basura: "${es.slice(0, 40)}"`);
cleaned++;
}
}
console.log(`\nLimpiadas ${cleaned} traducciones basura`);
console.log("Quedan limpias:", db.prepare("SELECT COUNT(*) c FROM posts WHERE title_es IS NOT NULL AND title_es != ''").get().c);
db.close();