Pywikibot/pagefromfile.py

From Wikibooks, open books for an open world
Jump to: navigation, search
Bug blank.svg
Git repository of Wikimedia has this file:

Pagefromfile.py is part of the pywikibot framework.

With this script you can create pages from a textfile.

The file should be in UTF-8 and if you want to create multiple pages from a file you should separate the articles as specified by the -start and -end arguments.

The pagename will be the first headword in your textfile (the first word between ''' '''). It is currently automatically inserted in the uploaded page.

WARNING: the script parses the input text in a recursive way, so it can easily run out of memory if the text contains several pages. It is advisable to break the input text into single pages and upload them individually.

Specific arguments:

arg Description Default
-start:xxxx Specify the text that is the beginning of a page {{-start-}}
-end:yyyy Specify the text that is the end of a page {{-stop-}}
-file:zzz Give the filename we are getting our material from dict.txt
-include The beginning and end text should be included in the page. do not include
-notitle Do not include the title line in the page. include title line
-titlestart:xxx Use xxx in place of ''' for identifying the beginning of the page title '''
-titleend:xxx Use xxx in place of ''' for identifying the end of the page title '''
-summary:xxx Use xxx as the summary for the upload.
Leave xxx empty so as to use mediawikis autosummary.
depending on language
-minor Set minor edit flag on page edits. not selected
-dry Do not really upload pages, just check and report messages. not selected
-safe If the page to be uploaded already exists, do nothing, i.e. skip it. -safe
-appendtop If the page to be uploaded already exists, add the text to the top of it.
-appendbottom If the page to be uploaded already exists, add the text to the bottom of it.
-force If the page to be uploaded already exists, overwrite the existing page.

E.g.: Filename.xml

xxxx
'''PageName'''
Text here

yyyy
xxxx
'''AnotherPageName'''
Another text
yyyy

Usage:

pagefromfile.py [global-arguments] -start:xxxx -end:yyyy -file:Filename.xml

Global arguments available for all bots

arg Description Default
-family:xyz Set the family of the wiki you want to work on, e.g. wikipedia, wiktionary, commons, wikitravel, …. This will override the configuration in user-config.py settings. user-config.py parameter: family
-lang:xx Set the language of the wiki you want to work on, overriding the configuration in user-config.py where xx should be the language code[1]. user-config.py parameter: mylang
-log Enable the logfile. Logs will be stored in the logs subdirectory. user-config.py parameter: log ?
-log:xyz Enable the logfile, using xyz as the filename.
-nolog Disable the logfile (if it's enabled by default).
-putthrottle:nn
-pt:nn
Set the minimum time (in seconds) the bot will wait between saving pages. user-config.py parameter: putthrottle ?
-verbose
-v
Make the program output more detailed messages than usual to the standard output about its current work, or progress, while it is proceeding. This may be helpful when debugging or dealing with unusual situations. not selected
  1. Commons uses 'commons' for lang and family; Meta uses 'meta' for both.