Created
February 28, 2024 23:47
-
-
Save ProbablePrime/95ff8ee591ae3e97b48015aa93c915a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { mwn } = require('mwn'); | |
function shouldIgnore(title) { | |
if (title === "Category:ProtoFlux") | |
return true; | |
if (title === "Category:ProtoFlux:All") | |
return true; | |
if (title === "Category:ProtoFluxStubs") | |
return true; | |
return false; | |
} | |
async function main() { | |
const bot = await mwn.init({ | |
apiUrl: 'https://wiki.resonite.com/api.php', | |
// Can be skipped if the bot doesn't need to sign in | |
username: 'GloopieBot', | |
password: 'A', | |
// Set default parameters to be sent to be included in every API request | |
defaultParams: { | |
assert: 'user' // ensure we're logged in | |
} | |
}); | |
const pages = await bot.getPagesByPrefix("Category:ProtoFlux"); | |
//console.log(pages); | |
for (let pageName of pages) { | |
if (shouldIgnore(pageName)) | |
continue; | |
const parts = pageName.split(':'); | |
// Category: part [0] | |
// ProtoFlux: part [1] | |
if (parts.length < 3) | |
continue; | |
// if (parts.length == 3) { | |
// const page = new bot.Page(pageName); | |
// let contents = await page.text(); | |
// if (contents.indexOf(`[[Category:ProtoFlux]]`) == -1) { | |
// contents = contents + "\n[[Category:ProtoFlux]]"; | |
// await bot.save(pageName, contents, "Cleaning ProtoFlux Categories"); | |
// } | |
// } | |
// if (parts.length == 4) { | |
// var end = parts.pop() | |
// const newCategory = parts.join(":"); | |
// const page = new bot.Page(pageName); | |
// let contents = await page.text(); | |
// const newCategoryText = `[[${newCategory}]]`; | |
// if (contents.indexOf(newCategoryText) == -1) { | |
// contents = contents + `\n${newCategoryText}`; | |
// await bot.save(pageName, contents, "Cleaning ProtoFlux Categories"); | |
// } | |
// } | |
if (parts.length == 5) { | |
console.log(parts); | |
var end = parts.pop() | |
console.log(parts); | |
const newCategory = parts.join(":"); | |
const page = new bot.Page(pageName); | |
let contents = await page.text(); | |
const newCategoryText = `[[${newCategory}]]`; | |
if (contents.indexOf(newCategoryText) == -1) { | |
contents = contents + `\n${newCategoryText}`; | |
await bot.save(pageName, contents, "Cleaning ProtoFlux Categories"); | |
} | |
} | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment