Руководство:Pywikibot/add text.py

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

This is a script which helps to add a text at the end of the page but above categories, interwiki and template for the stars of the interwiki (default setting), or add a text at the top of the page.

This needs Python with at least v2.7 as stated on Руководство:Pywikibot/Установка .

Параметры

These command line parameters can be used to specify which pages to work on:

-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

Another example:

$ 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:PATH Прочитать настройки бота из каталога, заданному переменной PATH, а не из каталога по умолчанию.  
-config:file The user config filename. Default is user-config.py. user-config.py
-lang:xx Установить язык Вики с которой вы хотите работать, перезаписывая конфигурацию из user-config.py. Вместо xx должен быть указан код языка (ru). mylang
-family:xyz Установите семейство Вики с которой вы хотите работать, например, Википедия, викисловарь, викисклад, викитрэвел, ... Переопределяет конфигурацию в user-config.py. family
-user:xyz Войдите в систему как пользователь 'xyz' вместо пользователя по умолчанию. usernames
-daemonize:xyz Немедленно возвращает управление терминалу и перенаправляет stdout и stderr в файл xyz (использовать только для ботов, которые не требуют ввода из stdin).  
-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
Переключает настройки cosmetic_changes в config.py или user-config.py в противоположные или отменяет их. Все остальные параметры и ограничения остаются без изменений. cosmetic_changes
-simulate Запрещается запись на сервер. Полезно для тестирования и отладки нового кода (если эта опция указана, не делается каких-либо реальных изменений, а только показывается, что изменилось бы). simulate
-<config var>:n Вы можете использовать все заданные числовые настройки переменных как параметр и изменить его из командной строки.