log index; add variable to resume partway through the list

This commit is contained in:
ewin 2025-08-12 18:49:30 -04:00
parent c0ae1f240f
commit e1004215e1
Signed by: erin
SSH key fingerprint: SHA256:swjoHhREbZPbWe+gyJNi24d4NAxJSyUIm3fpZj4z3wc

View file

@ -15,21 +15,26 @@ const mw = await getMediawikiClient();
// parse CSV, naively assume there are no quotes or backslashes (because i checked) // parse CSV, naively assume there are no quotes or backslashes (because i checked)
const data = readFileSync(join(import.meta.dirname, '../../hats.csv'), 'utf-8').split(/\r?\n/g).map(line => line && line.split(',')); const data = readFileSync(join(import.meta.dirname, '../../hats.csv'), 'utf-8').split(/\r?\n/g).map(line => line && line.split(','));
console.log(data.slice(0, 1));
const headers = data.splice(0, 1)[0]; const headers = data.splice(0, 1)[0];
const COL_ITEM = headers.findIndex(field => field.toLowerCase() === 'item'); const COL_ITEM = headers.findIndex(field => field.toLowerCase() === 'item');
const COL_VIERA = headers.findIndex(field => field.toLowerCase().includes('viera')); const COL_VIERA = headers.findIndex(field => field.toLowerCase().includes('viera'));
const COL_HROTH = headers.findIndex(field => field.toLowerCase().includes('hrothgar')); const COL_HROTH = headers.findIndex(field => field.toLowerCase().includes('hrothgar'));
const start = parseInt(process.env.START ?? '0', 10);
if (start) {
console.log('Starting from item index', start);
data.splice(0, start);
}
console.log('Processing', data.length, 'items'); console.log('Processing', data.length, 'items');
for (const line of data) { for (const [i, line] of Object.entries(data)) {
const item = line[COL_ITEM]; const item = line[COL_ITEM];
const params = { const params = {
'display-on-viera': line[COL_VIERA].toLowerCase() === 'yes' ? 'y' : 'n', 'display-on-viera': line[COL_VIERA].toLowerCase() === 'yes' ? 'y' : 'n',
'display-on-hrothgar': line[COL_HROTH].toLowerCase() === 'yes' ? 'y' : 'n', 'display-on-hrothgar': line[COL_HROTH].toLowerCase() === 'yes' ? 'y' : 'n',
} }
console.log(item, params); console.log(+i + start, 'of', data.length + start, item, params);
// read and apply updates // read and apply updates
const pageContent = await mw.readPage(item); const pageContent = await mw.readPage(item);