跳转到内容

User:CrowleyBot/lib/stop.py

維基詞典,自由的多語言詞典

示例代码。若启用,本人一定会在编辑摘要留下停止用链接,通常是讨论页。受信用户编辑链接页面,会使机器人在40笔编辑内停止。

import mwclient as mwc
import wikitextparser as wtp
import os, sys, time, re
import itertools as its
import more_itertools as mits
import zhconv as zhc
from mainaccount import *

zh = mwc.Site('zh.wiktionary.org', clients_useragent = UA)
zh.login(UN, PWD)
SLP = 0
n = len(pn)

p0 = zh.Pages['User:Qnm/0']
p1 = zh.Pages['User:Qnm/1']

LOCK = time.mktime(mits.nth(p0.revisions(), 0)['timestamp'])
for i in its.count(0, 1):
    p1.edit(i, '测试紧急停止')
    if i % 40 == 0:
        LASTR = mits.nth(p0.revisions(), 0)
        LASTT = time.mktime(LASTR['timestamp'])
        if LASTT > LOCK:
            LOCK = LASTT
            if LASTR['user'] in ['EdwardAlexanderCrowley']:
                uinfo = zh.get('query', list='users', usprop='groups|editcount', ususers=LASTR['user'])['query']['users'][0]
                ugroup = uinfo['groups']
                uedit = uinfo['editcount']
                if 'autoconfirmed' in ugroup and uedit > 100:
                    break