-
Notifications
You must be signed in to change notification settings - Fork 2
/
gans-lister.ts
47 lines (40 loc) · 1.21 KB
/
gans-lister.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { argv, bot, log, mwn } from '../botbase';
import { TOOLS_DB_HOST, toolsdb } from '../db';
import { closeTunnels, createLocalSSHTunnel, withIndices } from "../utils";
import { TABLE } from "./model";
(async function () {
await createLocalSSHTunnel(TOOLS_DB_HOST);
let db = new toolsdb('goodarticles_p');
let result = await db.query(`
SELECT nominator, COUNT(*) AS count
FROM ${TABLE}
GROUP BY nominator
ORDER BY count DESC, nominator ASC
LIMIT 600
`);
db.end();
log(`[S] Got query result`);
let wikitable = new mwn.table();
wikitable.addHeaders(['Rank', 'User', 'Count']);
let rank500Count;
for (let [idx, {nominator, count}] of withIndices(result)) {
let rank = idx + 1;
if (rank === 500) {
rank500Count = count;
} else if (rank > 500 && count < rank500Count) {
break;
}
wikitable.addRow([
String(rank),
`[[User:${nominator}|${nominator}]]`,
`[https://sdzerobot.toolforge.org/gans?user=${encodeURIComponent(nominator)} ${count}]`
]);
}
await bot.getTokensAndSiteInfo();
await bot.save(
'Wikipedia:List of Wikipedians by good article nominations' + (argv.sandbox ? '/sandbox' : ''),
'{{/header}}\n\n' + wikitable.getText()
);
log(`[S] Saved`);
closeTunnels();
})();