-
Notifications
You must be signed in to change notification settings - Fork 11
/
delete-unused-categories.py
executable file
·45 lines (33 loc) · 1.43 KB
/
delete-unused-categories.py
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
#! /usr/bin/env python3
from ws.client import API
from ws.utils import dmerge, RateLimited
from ws.interactive import require_login, ask_yesno
@RateLimited(1, 1)
def delete_page(api, title, pageid):
print("Deleting page '{}' (pageid={})".format(title, pageid))
api.call_with_csrftoken(action="delete", pageid=pageid, reason="Unused category", tags="wiki-scripts")
def main(args, api):
unused_categories = [p["title"] for p in api.list(list="querypage", qppage="Unusedcategories", qplimit="max")]
result = {}
query = api.call_api_autoiter_ids(action="query", prop="revisions", rvprop="content|timestamp", rvslots="main", titles=unused_categories)
for chunk in query:
dmerge(chunk, result)
pages = result["pages"]
for page in sorted(pages.values(), key=lambda p: p["title"]):
title = page["title"]
pageid = page["pageid"]
content = page["revisions"][0]["slots"]["main"]["*"]
print()
print(f"Unused category title: {title}")
print(f"Content:\n{content}\n")
delete = ask_yesno("Delete the page?")
if delete is True:
delete_page(api, title, pageid)
if __name__ == "__main__":
import ws.config
argparser = ws.config.getArgParser(description="Delete unused categories (interactive)")
API.set_argparser(argparser)
args = ws.config.parse_args(argparser)
api = API.from_argparser(args)
require_login(api)
main(args, api)