手册:Pywikibot/add text.py

From mediawiki.org
This page is a translated version of the page Manual:Pywikibot/add text.py and the translation is 37% complete.

此脚本可以协助添加文字,添加的位置在页面结尾的维护分类、跨维基链接和相关模板之前,或者添加在页面顶部。

这至少需要2.7及以上版本的python,正如Manual:Pywikibot/安装 所述。

参数

这些命令行参数可以用来指定要在哪些页面上操作:

-cat Targets entries within a specific category
-page Use a page as generator
-file Read a list of pages to treat from the named text file. Page titles in the file must be enclosed with brackets or separated by newlines. Argument can also be given as "-file:filename".

Furthermore, the following command line parameters are supported:

-text Define which text to add
-talkpage Put the text onto the talk page instead
-summary Define the summary to use
-except Use a regex to check if the text is already in the page **DEPRECATED IN 6.3.0 - Use "-grepnot" instead**
-excepturl Use the html page as text where you want to see if there's the text, not the wiki-page.
-newimages Add text in the new images
-untagged Add text in the images that don't have any license template
-always If used, the bot won't ask if it should add the text specified
-up If used, put the text at the very top of the page *
-noreorder Disable reordering of categories

For more command line parameters, run the bot help command for example: python pwb.py add_text -help | more

示例

Adding a template to specific pages

It will add the text "{{Documentation subpage}}" at the very top of the pages with "Category:Template documentation", except for those which already include it.

$ python pwb.py add_text -cat:template_documentation -text:"{{Documentation subpage}}" -grepnot:"\{\{([Tt]emplate:|)(\s|)[Dd]ocumentation [Ss]ubpage" -up
  • -cat:template_documentationonly target entries categorized in the page of "Category:Template documentation"
  • -text:"{{Documentation subpage}}"add the template "{{Documentation subpage}}" (excluding the quotes)
    • To insert return code, use "\n". But, if you use "-up" option, it becomes invalid.
  • -grepnot:"\{\{([Tt]emplate:|)(\s|)[Dd]ocumentation [Ss]ubpage"regex commands to exclude entries which have this template already in the page
  • -upput the text at the top of the page instead

另一个例子:

$ python pwb.py add_text -cat:catname -summary:"Bot: Adding a template" -text:"{{Something}}" -grepnot:"\{\{([Tt]emplate:|)(\s|)[Ss]omething" -up


Adding category to pages without any category

This is a real instance that is used on Wikipedia to put a template on a page without any category, because if there are any hidden categories, the page will be defined as categorized.

$ python pwb.py add_text -excepturl:"class='catlinks'>" -uncat -text:"{{Categorizzare}}" -grepnot:"\{\{([Tt]emplate:|)[Cc]ategorizzare" -summary:"Bot: Aggiungo template Categorizzare"


可用的全域參數

这些选项将覆盖user-config.py 设置中的配置。

全域选项
参数 描述 配置变量
-dir:路径 从路径给出的目录中读取bot的配置数据,而不是从默认目录中读取。  
-config:file The user config filename. Default is user-config.py. user-config.py
-lang:xx 设置要使用的wiki的语言,覆盖user-config.py中的配置。xx应该是语言代码。 mylang
-family:xyz 设置你想要工作的wiki的系列,例如维基百科,维基词典,维基导游,...... 这将覆盖user-config.py中的配置。 family
-user:xyz 以用户'xyz'而不是默认用户名登录。 usernames
-daemonize:xyz 控制权立即交回终端,标准输出(stdout)和标准错误(stderr)重定向到文件xyz。(仅用于不需要从“标准输入”输入内容的机器人)。  
-help 显示帮助文本。  
-log 启用日志文件,默认文件名“script_name-bot.log”,日志存储在logs子目录中。 log
-log:xyz 启用日志文件,文件名'xyz'。 logfilename
-nolog 禁用日志文件(如果默认启用)。  
-maxlag 设置新的maxlag参数,单位秒。 数据库服务器高压力时机器人编辑的延迟秒数。config.py中设置有默认值。 maxlag
-putthrottle:n
-pt:n
-put_throttle:n
设置机器人在保存页面之间的最小间隔时间(单位:秒)。 put_throttle
-debug:item
-debug
启用日志文件并包括“item”组件的广泛调试数据(如果使用形式二,则包括所有组件)。 debug_log
-verbose
-v
使机器人提供额外的控制台输出内容,这可能对调试有益。 verbose_output
-cosmeticchanges
-cc
切换config.py或user-config.py中的cosmetic_changes设置,使其反转。 其他设置和限制不受影响。 cosmetic_changes
-simulate 禁用对服务器的写入。 适合用于测试和调试新编写的代码(如果设置,不会做任何实际更改,只显示将更改的内容)。 simulate
-<config var>:n 您可以使用所有给定的数字配置变量作为选项,并使用命令行进行修改。