Beispiel #1
0
def main():
    page = wp.handlearg("page", args)
    if page:
        page = wp.Page(page)
        page.put(lcleaner.clean(page.get()), conf.summary)
    txt = wp.handlearg("txt", args)
    if txt:
        pywikibot.output(lcleaner.clean(txt))
Beispiel #2
0
def main():
    config = wp.ReadCode(wp.Page(conf.title), "config")
    config.load()
    config = config.data
    for page in dict(config):
        config[wp.Page(page)] = dict(config[page])
        del config[page]
    updateList = [wp.handlearg("page", args)]
    partial = False
    if updateList[0]:
        partial = True
    else:
        updateList = config.keys()
    for ind, page in enumerate(updateList):
        if not isinstance(page, pywikibot.Page):
            updateList[ind] = wp.Page(page)
    
    updateList = list(site.preloadpages(updateList))
    
    sources = [wp.Page(value['source']) for value in config.values()]
    
    if not partial:
        out = []
        for psite, subgroup in itertools.groupby(sources, lambda x: x.site):
            out += list(psite.preloadpages(subgroup))
        sources = out

    sources = {m: m for m in sources}

    for page in updateList:
        process(page, config[page], sources) # normalize page's name
Beispiel #3
0
def main():
    if args:
        gen = [wp.Page(wp.handlearg("page", args))]
    else:
        gen = pywikibot.Category(site, u'กล่องนำทางที่ไม่ได้ใช้รายการแนวนอน').articles()
    namespass = libinfo.getdat(filename=u"passlist", key=u"name")
    namespass = filter(lambda x: x, 
            [x.strip() for x in (namespass if namespass else "").split(u" ")])
    for page in gen:
        print ">>>", page.title()
        if not page.title().startswith(u"แม่แบบ:"):
            continue
        
        if page.title().replace(u" ", u"_") in namespass:
            print "pass!"
            continue
        try:
            text = page.get()
        except:
            preload.error()
            continue
        
        addlistclass = True
        addhlist = True
        if u"listclass" in text:
            addlistclass = False
        
        if u"hlist" in text:
            addhlist = False
        
        print "listclass :", addlistclass, "hlist :", addhlist, 
        
        if addlistclass and addhlist:
            text = text.replace(u"กล่องท้ายเรื่องใหม่", u"navbox")
            text = patintclass.sub(u"| title = \\1\n| listclass = hlist", text)
            odiff = text
            text = patwrap.sub(u"\\1", text)
            text = patdel.subr(u"\\1\n* ", text)
            text = patnl.sub(u"\\1 = \n* ", text)
            text = triml.sub(u"\n", text)
            text = patbr.sub(u"\\1", text)
            text = patopen.sub(u"\\1\n* [[", text)
            text = patclose.sub(u"]]\n\\1", text)
            text = text.replace(u" ", u"")
            text = patrmwrap.sub(u"", text)
            
            #text = patfix.sub(, text)
            print text
            print "------------"
            pywikibot.showDiff(odiff, text)
            print "------------"
            print ">>>", page.title()
            response = raw_input("Should proceed?: ")
            if response == 'y' or response == '':
                page.put(text, u"ปรับปรุงแม่แบบ Navbox")
            elif response == 'p':
                namespass.append(page.title().replace(u" ", u"_"))
                libinfo.putdat(filename=u"passlist", key=u"name", 
                                value=" ".join(namespass))
Beispiel #4
0
def main():
    page = wp.handlearg("page", args)
    if page:
        page = wp.Page(page)
        dic = page.getVersionHistory(reverseOrder=True, total=1)
        gen = [{"user": dic[0][2], "title": page.title()}]
        check = wp.handlearg("check", args)
        if check:
            check = wp.Page(check)
    else:
        gen = lrepeat.repeat(site, site.recentchanges, lambda x: x["revid"],
                             60, showRedirects=False, changetype=["new"],
                             showBot=False, namespaces=[0])
    for rev in gen:
        try:
            process(wp.Page(rev["title"]), check, wp.User(rev["user"]))
        except:
            wp.error()
Beispiel #5
0
def main():
    pool = lthread.ThreadPool(30)
    gen = []
    page = wp.handlearg("page", args)
    if page is not None:
        gen = [wp.Page(page)]
    else:
        gen = site.allpages(prefix=conf.title, content=True, namespace=2)
    for page in gen:
        for req in lre.pats["entry"].finditer(page.get()):
            pool.add_task(process, req.group(1), page.title())
    pool.wait_completion()
Beispiel #6
0
def process(lst):
    exist = site.pagesexist([x.toggleTalkPage().title() for x in lst])
    for i, page in enumerate(lst):
        if not exist[i][0]:
            if "/" in page.title():
                if page.parentPage().toogleTalkPage().exists():
                    continue
                elif wp.handlearg("manual", args):
                    continue

            if page.botMayEdit() and (site.getcurrenttime() - page.editTime()).days >= 30:
                pywikibot.output("deleting " + page.title())
                page.delete(reason=u"โรบอต: หน้าขึ้นกับหน้าว่าง", prompt=False)
            else:
                pywikibot.output("can't delete " + page.title())
Beispiel #7
0
def main():
    pool = lthread.ThreadPool(30)
    gen = []
    page = wp.handlearg("page", args)
    if page is not None:
        gen = [wp.Page(page)]
    else:
        gen = site.allpages(prefix=conf.title, content=True, namespace=2)
    for page in gen:
        for req in lre.pats["entry"].finditer(page.get()):
            pool.add_task(process, req.group(1), page.title())
    pool.wait_completion()
    #print allo
    global allo
    allo =  '<source lang="python">\n' + allo + u'</source>{{คู่มือการใช้งาน}}'
    wp.Page(u'User:Nullzerobot/ปรับปรุงหน้าอัตโนมัติ/ปกติ').put(allo, u"ปรับปรุงหน้า")
Beispiel #8
0
def main():
    user = {}
    seen = set()
    start = site.getcurrenttime()
    delta = wp.handlearg("delta", args)
    if delta:
        start -= ltime.td(int(delta))
    config = wp.ReadCode(wp.Page(u"ผู้ใช้:Nullzerobot/ปูมการละเมิด"), "config")
    while True:
        oldConfig = dict(config.data)
        config.load()
        if oldConfig != config.data:
            pywikibot.output(">>> reload new config!")
        for i in config.data:
            data = config.data[i]
            for ab in site.abuselog(reverse=True, abuseid=i, start=start, as_group='sysop'):
                if (ab["id"]) in seen:
                    continue
                seen.add(ab["id"])
                pywikibot.output("filter: %s\t\tuser: %s\t\ttime: %s" %
                                (i, ab["user"].ljust(16), ab["timestamp"]))
                userobj = wp.User(ab["user"])
                if userobj.editCount() >= 5000:
                    continue
                if userobj.name() not in user:
                    user[userobj.name()] = {}
                if i not in user[userobj.name()]:
                    user[userobj.name()][i] = deque()
                deq = user[userobj.name()][i]
                deq.append(pywikibot.Timestamp.fromISOformat(ab["timestamp"]))
                now = site.getcurrenttime()
                while deq and ((now - deq[0]).seconds >= data["checkDuration"]):
                    deq.popleft()
                pywikibot.output(list(deq))
                if len(deq) >= data["threshold"]:
                    process(userobj, data, ab)
                    deq.clear()
        if delta:
            break
        ltime.sleep(60)
        start = max(start, site.getcurrenttime() - ltime.td(seconds=120))
Beispiel #9
0
def main():
    """Main function"""
    if wp.handlearg("pending", args):
        pywikibot.output("move pending entry")
        title = conf.pageMinor
        operation = "minor"
    else:
        title = conf.pageMajor
        operation = "major"

    header, table, disable = lservice.service(page=wp.Page(title),
                                              confpage=wp.Page(conf.datwiki),
                                              operation=operation,
                                              verify=verify,
                                              summary=summaryWithTime,
                                              #debug=True,
                                              )

    report = []
    pending = []

    for i, line in enumerate(table):
        putline = "|-\n| " + " || ".join(line)
        if (operation == "minor") or (not disable[i]):
            templateStat = conf.notDoneTemplate

            try:
                domove(lre.pats["name"].find(line[1], 1),
                       lre.pats["name"].find(line[2], 1))
            except:
                wp.error()
            else:
                templateStat = conf.doneTemplate

            putline += " || %s %s" % (templateStat, wp.getTime())
            report.append(putline)
        else:
            pending.append(putline)

    appendTable(conf.pageReport, report)
    appendTable(conf.pageMinor, pending)