log index; add variable to resume partway through the list
This commit is contained in:
parent
c0ae1f240f
commit
e1004215e1
1 changed files with 8 additions and 3 deletions
|
|
@ -15,21 +15,26 @@ const mw = await getMediawikiClient();
|
|||
|
||||
// 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(','));
|
||||
console.log(data.slice(0, 1));
|
||||
const headers = data.splice(0, 1)[0];
|
||||
const COL_ITEM = headers.findIndex(field => field.toLowerCase() === 'item');
|
||||
const COL_VIERA = headers.findIndex(field => field.toLowerCase().includes('viera'));
|
||||
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');
|
||||
|
||||
for (const line of data) {
|
||||
for (const [i, line] of Object.entries(data)) {
|
||||
const item = line[COL_ITEM];
|
||||
const params = {
|
||||
'display-on-viera': line[COL_VIERA].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
|
||||
const pageContent = await mw.readPage(item);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue