Manual:Pywikibot/pagefromfile.py

From MediaWiki.org
Jump to: navigation, search

Other languages:
العربية • ‎čeština • ‎English • ‎français • ‎italiano • ‎日本語 • ‎polski
Git-logo.svg
Wikimedia Git repository has this file: scripts/pagefromfile.py

pagefromfile.py is a PywikibotManual:Pywikibot script used to upload pages to a wiki from a text file.

This bot takes its input from the UTF-8 text file that contains a number of pages to be put on the 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.

As a page name is by default taken the first text block from the page content marked in bold (wrapped between ''' and '''). If you expect the page title not to be present in the text or marked by different markers, use -titlestart, -titleend, and -notitle parameters.

Specific arguments[edit]

Parameter Description
-file:xxx The filename we are getting our material from, the default value is "dict.txt"
-begin:xxx The text that marks the beginning of a page, the default value is "{{-start-}}"
-end:xxx The text that marks the end of the page, the default value is "{{-stop-}}"
-include Include the beginning and end markers to the page
-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
-nocontent:xxx If the existing page contains specified statement, the page is skipped from editing
-noredirect Do not upload on redirect pages
-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 Set the minor edit flag on page edits
-showdiff Show difference between current page and page to upload, also forces the bot to ask for confirmation on every edit

If the page to be uploaded already exists, it is skipped by default. But you can override this behavior if you want to:

Parameter Description
-appendtop Add the text to the top of the existing page
-appendbottom Add the text to the bottom of the existing page
-force Overwrite the existing page

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.

Examples[edit]

Basic example[edit]

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.

Different page titles[edit]

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.


<translate> Global arguments available for all bots</translate>

<translate> These options will override the configuration in {{<tvar|user-config.py>ll|Manual:Pywikibot/user-config.py</>|user-config.py}} settings. </translate>

<translate> Parameter</translate> <translate> Description</translate> <translate> Config variable</translate>
-dir:<translate> PATH</translate> <translate> Read the bot's configuration data from directory given by PATH, instead of from the default directory.</translate>
-lang:xx <translate> Set the language of the wiki you want to work on, overriding the configuration in <tvar configfile>user-config.py</>. <tvar
-family:xyz <translate> Set the family of the wiki you want to work on, e.g. wikipedia, wiktionary, wikitravel, ... This will override the configuration in <tvar configfile>user-config.py</>.</translate>
-user:xyz <translate> Log in as user '<tvar xyz>xyz</>' instead of the default username.</translate>
-daemonize:xyz <translate> Immediately return control to the terminal and redirect stdout and stderr to file <tvar xyz>xyz</>. (only use for bots that require no input from stdin).</translate>
-help <translate> Show the help text.</translate>
-log <translate> Enable the log file, using the default filename 'script_name<tvar -bot.log>-bot.log</>' Logs will be stored in the logs subdirectory.</translate>
-log:xyz <translate> Enable the log file, using '<tvar xyz>xyz</>' as the filename.</translate>
-nolog <translate> Disable the log file (if it is enabled by default).</translate>
-maxlag <translate> 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</translate> maxlag
-putthrottle:n
-pt:n
-put_throttle:n
<translate> Set the minimum time (in seconds) the bot will wait between saving pages.</translate> put_throttle
-debug:item
-debug
<translate> Enable the log file and include extensive debugging data for component "item" (for all components if the second form is used).</translate> debug_log
-verbose
-v
<translate> Have the bot provide additional console output that may be useful in debugging.</translate> verbose_output
-cosmeticchanges
-cc
<translate> Toggles the <tvar cosmetic>cosmetic_changes</> setting made in <tvar
-simulate <translate> 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).</translate> simulate
-<<translate> config var</translate>>:n <translate> You may use all given numeric config variables as option and modify it with command line.</translate>