Manual:Pywikibot/pagefromfile.py
Wikimedia Git repository has this file: scripts/pagefromfile.py |
pagefromfile.py é um script do Pywikibot usado para enviar páginas a uma wiki a partir de um arquivo de texto.
Esse robô recebe como entrada (input) um arquivo de texto em UTF-8 que contenha um número de páginas a serem inseridas na wiki. The pages should all have the same beginning and ending text (which may not overlap). The beginning and ending text is not uploaded with the page content by default.
Por padrão, o nome da página é tomado a partir do primeiro trecho de texto da página marcado em negrito (ou seja, envolto por ''' e ''').
If you expect the page title not to be present in the text or marked by different markers, use -titlestart
, -titleend
, and -notitle
parameters.
Argumentos específicos
Parameter | Description |
---|---|
-file:xxx |
Nome do arquivo do qual estaremos obtendo o material. Seu valor padrão é “dict.txt”. Notice that if the source file name contains any space character, you should wrap it with double quotations (i.e. -file:"Page title" ). |
-begin:xxx |
Texto que marca o início de uma página. Seu valor padrão é “{{-start-}}”. |
-end:xxx |
Texto que marca o fim de uma página. Seu valor padrão é “{{-stop-}}”. |
-include |
Inclua nos marcadores de início e fim da página. |
-textonly |
Text is given without markers. Only one page text is given. -begin and -end options are ignored. |
-titlestart:xxx |
The text used in place of ''' for identifying the beginning of a page title |
-titleend:xxx |
The text used in place of ''' for identifying the end of the page title |
-notitle |
Do not include the page title, including titlestart and titleend, to the page. Can be used to specify unique page title above the page content |
-title:xxx |
The page title is given directly. Ignores -titlestart, -titleend and -notitle options |
-nocontent:xxx |
If the existing page contains specified statement, the page is skipped from editing |
-noredirect |
Não envia alterações em páginas de redirecionamento |
-summary:xxx |
The text used as an edit summary for the upload. If the page exists, standard messages for prepending, appending, or replacement are appended after it |
-autosummary |
Use MediaWiki's autosummary when creating a new page, overrides -summary |
-minor |
Coloca a etiqueta de edição menor na página de edições |
-showdiff |
Mostra a diferença entre a página atual e a página a ser enviada, também força o bot a pedir confirmação em cada edição |
Se a página a ser carregada já existe, ela é ignorada por padrão. Mas você pode anular este comportamento se quiser:
Parameter | Description |
---|---|
-appendtop |
Adiciona o texto ao topo da página existente |
-appendbottom |
Adiciona o texto ao final da página existente |
-force |
Sobrepõe a página existente |
It is possible to define a separator after the 'append' modes which is added between the existing and the new text.
For example a parameter -appendtop:foo
would add 'foo' between them.
A new line can be added between them by specifying '\n' as a value.
Exemplos
Exemplo básico
In the most basic form, pagefromfile takes a single text file with several wiki pages in it as input. For example, the contents could be:
{{-start-}}
'''Pywikibot''' is a Python library and collection of scripts that automate work on MediaWiki sites.
Originally designed for Wikipedia, it is now used throughout the Wikimedia Foundation's projects and on many other wikis.
{{-stop-}}
{{-start-}}
'''AutoWikiBrowser''' (often abbreviated '''AWB''') is a semi-automated MediaWiki editor designed to make tedious or repetitive editing tasks quicker and easier.
{{-stop-}}
Store this as a UTF-8 encoded text file, for example as 'pages.txt'.
You can then run python pwb.py pagefromfile -showdiff -file:pages.txt
.
This will let the bot create Pywikibot and AutoWikiBrowser -- the first '''bolded''' elements in both pages.
-showdiff
will give you the opportunity to review changes before they are being made.
Diferentes títulos de páginas
Often, the first bolded element is not necessarily the correct page title. For example, we might want to place the article about AutoWikiBrowser on AWB instead. To do so, add a line in front of each article, with the correct page title between triple quotes (i.e., bolded):
{{-start-}}
'''Pywikibot'''
'''Pywikibot''' is a Python library and collection of scripts that automate work on MediaWiki sites.
Originally designed for Wikipedia, it is now used throughout the Wikimedia Foundation's projects and on many other wikis.
{{-stop-}}
{{-start-}}
'''AWB'''
'''AutoWikiBrowser''' (often abbreviated '''AWB''') is a semi-automated MediaWiki editor designed to make tedious or repetitive editing tasks quicker and easier.
{{-stop-}}
and add the -notitle
parameter to the call, i.e.: python pwb.py pagefromfile -showdiff -file:pages.txt -notitle
.
Global arguments available
Esta página está desatualizada. |
These options will override the configuration in user-config.py settings.
Parameter | Description | Config variable |
---|---|---|
-dir:PATH |
Read the bot's configuration data from directory given by PATH, instead of from the default directory. | |
-config:file |
The user config filename. Default is user-config.py. | user-config.py |
-lang:xx |
Set the language of the wiki you want to work on, overriding the configuration in user-config.py. xx should be the language code. | mylang |
-family:xyz |
Set the family of the wiki you want to work on, e.g. wikipedia, wiktionary, wikitravel, ... This will override the configuration in user-config.py. | family |
-user:xyz |
Log in as user 'xyz' instead of the default username. | usernames |
-daemonize:xyz |
Immediately return control to the terminal and redirect stdout and stderr to file xyz. (only use for bots that require no input from stdin). | |
-help |
Show the help text. | |
-log |
Enable the log file, using the default filename 'script_name-bot.log' Logs will be stored in the logs subdirectory. | log |
-log:xyz |
Enable the log file, using 'xyz' as the filename. | logfilename |
-nolog |
Disable the log file (if it is enabled by default). | |
-maxlag |
Sets a new maxlag parameter to a number of seconds. Defer bot edits during periods of database server lag. Default is set by config.py | maxlag |
-putthrottle:n -pt:n -put_throttle:n |
Set the minimum time (in seconds) the bot will wait between saving pages. | put_throttle |
-debug:item -debug |
Enable the log file and include extensive debugging data for component "item" (for all components if the second form is used). | debug_log |
-verbose -v |
Have the bot provide additional console output that may be useful in debugging. | verbose_output |
-cosmeticchanges -cc |
Toggles the cosmetic_changes setting made in config.py or user-config.py to its inverse and overrules it. All other settings and restrictions are untouched. | cosmetic_changes |
-simulate |
Disables writing to the server. Useful for testing and debugging of new code (if given, doesn't do any real changes, but only shows what would have been changed). | simulate |
-<config var>:n |
You may use all given numeric config variables as option and modify it with command line. |