From 4a08492d25b3b0b87d993d03feee1a3e8c9ab8d9 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Wed, 16 Oct 2024 15:11:10 +0530 Subject: [PATCH] category-cycles: allow running for other wikis --- category-cycles/README.md | 7 ++++++- category-cycles/prettify.js | 8 ++++++++ category-cycles/run.sh | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/category-cycles/README.md b/category-cycles/README.md index 6486749..258cd8a 100644 --- a/category-cycles/README.md +++ b/category-cycles/README.md @@ -2,7 +2,12 @@ Used to generate [User:SDZeroBot/Category_cycles](https://en.wikipedia.org/wiki/User:SDZeroBot/Category_cycles). -Run using `bash run.sh`. +Run using `bash run.sh`. + +To run for a wiki other than enwiki, pass in the environment variables: +* DB +* API_URL +* OAUTH2_ACCESS_TOKEN Files: - get_edges.sql: Get a list of all parentcat—subcat connections through the database, with only the category page IDs for efficiency in the next step. diff --git a/category-cycles/prettify.js b/category-cycles/prettify.js index 3491d95..90dc57b 100644 --- a/category-cycles/prettify.js +++ b/category-cycles/prettify.js @@ -12,6 +12,14 @@ const PAGE_LEAD = `{{User:SDZeroBot/Category cycles/header}}\n`; process.chdir(__dirname); +// Allow running for other wikis as well +if (process.env.apiUrl) { + bot.setOptions({ + apiUrl: process.env.API_URL, + OAuth2AccessToken: process.env.OAUTH2_ACCESS_TOKEN + }); +} + // sort cycles by length as we're more interested in the smaller cycles let cycles = require('./cycles.json').sort((a, b) => a.length - b.length); diff --git a/category-cycles/run.sh b/category-cycles/run.sh index a569b41..72a426d 100644 --- a/category-cycles/run.sh +++ b/category-cycles/run.sh @@ -2,7 +2,7 @@ cd "./SDZeroBot/category-cycles" -cat get_edges.sql | sql enwiki --skip-column-names > edges.out +cat get_edges.sql | sql "${DB:-enwiki}" --skip-column-names > edges.out echo "Got edges\n" # add a -1 at the end for the cpp program to detect end of input