For faster navigation, this Iframe is preloading the Wikiwand page for 用户:LittleBot/stubbot.py.

用户:LittleBot/stubbot.py

#!/usr/bin/python
# -*- coding: utf-8  -*-

import wikipedia
import login,catlib
import pagegenerators
import sys
import re

def workon(page,stub_template = u"小作品", stub_redirect_template=[u"stub"], stub_category_name=u"Category:小作品"):
    replace_text = u""
    template_status = 0
    
    listTemplates = page.templates()
   
    # Avoid mistake
    stub_template = stub_template[0].upper() + stub_template[1:]

    for template_name in listTemplates:
       if template_name == stub_template:
             template_status = 2

       stub_template_lower = stub_template[0].lower() + stub_template[1:]
       if template_name == stub_template_lower:
             # Pass, for convince
	     template_status = 2

       for stub_redirect_name in stub_redirect_template:
             reTemplate = re.compile(u'[' + stub_redirect_name[0].upper() + stub_redirect_name[0].lower() + ']' + stub_redirect_name[1:] + '$')
             if reTemplate.search(template_name):
                 # Pass, for convince
                 template_status = 2

    try:
        # Get the page content
        text = page.get()
    except wikipedia.IsRedirectPage:
        # Oh no, this is a redirect page :(
        wikipedia.output(u"< SKIP > [[%s]]: Oh no, this is a redirect page :("%page.title())
        return

    # Remove interwiki links for a while
    if not mysite.lang in mysite.family.categories_last:
       interwikiLinks = wikipedia.getLanguageLinks(text, insite = mysite)
       text = wikipedia.removeLanguageLinks(text, site = mysite)

    # Get and remove category links
    categoryList = page.categories()
    text = wikipedia.removeCategoryLinks(text, site = mysite)

    # If there's no template:
    if template_status==0:
        mySummary = u"Robot: 新增小作品模板、整理"
        wikipedia.output(u"<CASE:0> [[%s]]: Will ADD stub template and arrange"%page.title())

        # Add Template
	text = text + u"\n((" + stub_template +"))\n"

    # If template exist, but not appropiate:
    elif template_status==1:
        mySummary = u"Robot: 更改小作品模板、整理"
        RtemplateOld = re.compile(u'(((msg:)?'+ replace_text +'(\|(.+?))?))', re.DOTALL)
        text = RtemplateOld.sub("((" + stub_template +"))",text)
        wikipedia.output(u"<CASE:1> [[%s]]: Will CHANGE stub template and arrange"%page.title())
    else:
        mySummary = u"Robot: 整理小作品"
        wikipedia.output(u"<CASE:2> [[%s]]: Will ARRANGE only"%page.title())

    # Arrange Category
    for categoryItem in categoryList:
        if categoryItem.title() == stub_category_name:
            categoryList.remove(categoryItem)
        
    text = wikipedia.replaceCategoryLinks(text ,categoryList, site = mysite)
        
    # Re-add interwiki links
    text = wikipedia.replaceLanguageLinks(text, interwikiLinks, site = mysite)

    # Here go edit text in whatever way you want. If you find you do not
    # want to edit this page, just return
    
    if text != page.get():
        page.put(text,mySummary) # Adding a summary text would be good
        wikipedia.output(u"<  OK  > [[%s]]: OK!"%page.title())
        if test:
            wikipedia.input(u"Changed [[%s]]. Press enter to continue."%page.title())

try:
    start = []
    test = False
    for arg in wikipedia.handleArgs():
        if arg.startswith("-test"):
            test = True
        else:
            start.append(arg)
    if start:
        start = " ".join(start)
    else:
        start = "!"
    
    # Start
    wikipedia.output(u"這是笨笨的小B所寫的小作品處理程式。由DoggyBot負責執行。")

    # Connect to Chinese Wikipedia, then login
    mysite = wikipedia.Site('zh')
    login.LoginManager('mh1810sd', False, mysite)
    
    # Here We Go!
    page=wikipedia.Page(mysite,u'User:DoggyBot/測試區2')
    workon(page,u"Bio-stub",[u"人物小作品",u"People-stub"],u"Category:人物小作品")


finally:
    wikipedia.stopme()
{{bottomLinkPreText}} {{bottomLinkText}}
用户:LittleBot/stubbot.py
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?