forked from ONI-Wiki-zh/BotNotIncluded
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot_mvns.py
More file actions
28 lines (22 loc) · 770 Bytes
/
bot_mvns.py
File metadata and controls
28 lines (22 loc) · 770 Bytes
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
# move namespace
import pywikibot
def mvns(site: pywikibot.Site, old_ns: int, new_ns: int):
pages = list(site.allpages(namespace=old_ns, content=True))
old_name = site.namespace(old_ns)
new_name = site.namespace(new_ns)
for i, p in enumerate(pages):
if i % 10 == 0:
print(i)
p: pywikibot.Page
try:
old_p: pywikibot.Page = list(site.load_pages_from_pageids([p.pageid]))[0]
old_p.move(
f"{new_name}:{p.title(with_ns=False)}",
reason=f"{old_name} => {new_name}",
noredirect=True)
except Exception as e:
print(e)
if __name__ == '__main__':
mblq = pywikibot.Site("zh", "zhblq")
mblq.login()
mvns(mblq, 3001, 503)