コード例 #1
0
ファイル: liblang.py プロジェクト: nullzero/wp
def fixRepetedVowelTitle(page):
    """
    If found impossible vowel arrangement in title, 
    correct by moving that page.
    """
    opagetitle = page.title()
    pagetitle = opagetitle
    
    for i in checkVowel:
        pagetitle = re2.sub(i + u"+", i, pagetitle)
    
    if pagetitle != opagetitle:
        pywikibot.output("ย้ายบทความชื่อมีสระซ้อน")
        reason = u"โรบอต: เปลี่ยนชื่อบทความมีสระซ้อน"
        try: 
            page.move(pagetitle, reason=reason)
        except:
            preload.error()
        else:
            page = pywikibot.Page(pywikibot.getSite(), page.title())
            page.delete(reason=reason, prompt=False, mark=True)
コード例 #2
0
ファイル: liblang.py プロジェクト: nullzero/wp
def fixRepetedVowel(content):
    """If found impossible vowel arrangement in text, correct it."""
    for i in checkVowel:
        content = re2.sub(i + u"+", i, content)
    return content
コード例 #3
0
ファイル: libservice.py プロジェクト: nullzero/wp
def service(serviceTitle, operation, verifyFunc, datwiki, site, summary, 
            debug=False):
    """
    Get:
        Title of service"s page
        Key to read from config page,
        Function to verify user
        Config page, site
        Summary function.

    Function:
        Clear service"s page

    Return:
        Header of table
        List of rows
        Suspicious entry(/row)
    """
    page = pywikibot.Page(site, serviceTitle)
    datwiki = pywikibot.Page(site, datwiki)
    lastrev = int(libinfo.getdat(key = operation, wikipage = datwiki))
    oldcontent = page.get()
    header, table = libwikitable.wiki2table(oldcontent)
    disable = [False] * len(table)
    hist = page.getVersionHistory()
    # There is no need to get all revisions, just 500 is fine (by default).
    histlist = []

    for version in hist:
        histlist.append((version, page.getOldVersion(version[0])))
        if version[0] == lastrev:
            break
    hist = histlist
    hist.reverse()
    pywikibot.output(u"Processing %d revision(s)" % len(hist))
    for i in xrange(len(hist) - 1):
        oldv = hist[i][1]
        newv = hist[i + 1][1]
        usernew = hist[i + 1][0][2]
        dummy, cold = libwikitable.wiki2table(oldv)
        dummy, cnew = libwikitable.wiki2table(newv)
        oldvc = set([preload.enunicode(x) for x in cold])
        newvc = set([preload.enunicode(x) for x in cnew])
        difference = [eval(x) for x in (newvc - oldvc)]
        if not verifyFunc(usernew):
            for entry in difference:
                for cnt, fentry in enumerate(table):
                    if entry == fentry:
                        disable[cnt] = True
                        break

    newcontent = re2.sub(ur"(?ms)^(\!.*?$\n).*?(^\|\})", ur"\1\2", oldcontent)

    if oldcontent != newcontent:
        if not debug:
            page = pywikibot.Page(site, page.title())
            page.put(newcontent, summary())
        
        print page.getVersionHistory()[0][0]
        libinfo.putdat(key=operation, 
                        value=page.getVersionHistory()[0][0], 
                        wikipage=datwiki)
                        
    return header, table, disable