move one-offs to subfolder; add better note about hroth/viera script
This commit is contained in:
parent
dc1c1514a6
commit
c0ae1f240f
2 changed files with 12 additions and 10 deletions
|
|
@ -1,69 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import {readFileSync} from 'node:fs';
|
||||
import {join} from 'node:path';
|
||||
|
||||
import {getMediawikiClient} from '../lib/config.js';
|
||||
import {diff} from '../lib/util/diff.js';
|
||||
import {addParameterAtBottom, setExistingParameter} from '../lib/util/template-parameters.js';
|
||||
|
||||
const mw = await getMediawikiClient();
|
||||
|
||||
// parse CSV
|
||||
// hats.csv is an export of this google sheet that crye compiled:
|
||||
// https://docs.google.com/spreadsheets/d/13s_qxWThsensslulLfAxN0-hzQZVCqS9fKaImlLXbVU/edit?gid=38787585#gid=38787585
|
||||
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'));
|
||||
|
||||
console.log('Processing', data.length, 'items');
|
||||
|
||||
for (const line of 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);
|
||||
|
||||
// read and apply updates
|
||||
const pageContent = await mw.readPage(item);
|
||||
let newPageContent = pageContent;
|
||||
try {
|
||||
for (const [paramName, paramValue] of Object.entries(params)) {
|
||||
newPageContent = setExistingParameter(newPageContent, paramName, paramValue)
|
||||
?? addParameterAtBottom(newPageContent, paramName, paramValue);
|
||||
|
||||
if (!newPageContent) {
|
||||
console.log(pageContent);
|
||||
throw new Error('adding parameter to the page failed');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.log('skipping this item');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (newPageContent === pageContent) {
|
||||
// no changes
|
||||
console.log('No changes, skipping');
|
||||
continue;
|
||||
}
|
||||
|
||||
diff(pageContent, newPageContent);
|
||||
|
||||
// write
|
||||
try {
|
||||
await mw.editPage(item, newPageContent, 'Add Hrothgar/Viera headwear data');
|
||||
} catch (error) {
|
||||
console.error('Failed to write:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('Written.');
|
||||
}
|
||||
|
||||
console.log('done!');
|
||||
Loading…
Add table
Add a link
Reference in a new issue