Manual:Pywikibot/upload.py

From MediaWiki.org
Jump to: navigation, search
Wikimedia-logo-meta.png

This page was moved from MetaWiki.
It probably requires cleanup – please feel free to help out. In addition, some links on the page may be red; respective pages might be found at Meta. Remove this template once cleanup is complete.

Bug blank.svg
Wikimedia Git repository has this file:
compat: upload.py

upload.py is a Pywikipediabot script used to upload images to a wiki.

Usage[edit | edit source]

python upload.py [Global-arguments] [-keep] [-filename:targetFilename] [-noverify] [URL-or-filename [description-text]]

Arguments[edit | edit source]

-keep Keep the filename as is
-filename Target filename
-noverify Do not ask for verification of the upload description if one is given

If any other arguments are given, the first is the URL or filename to upload, and the rest is a proposed description to go with the upload. If none of these are given, the user is asked for the file or URL to upload. The bot will then upload the image to the wiki.

The script will ask for the location of an image, if not given as a parameter, and for a description.

If the -filename argument is given, then it is used as the name of the image on the wiki; otherwise it is based on the filename or url of the input file.

If -keep is not specified, then the target filename undergoes some further checking, and the user is asked for confirmation. The / character is forbidden, and the filename extension (after the dot) must be one of these: gif, jpg, jpeg, mid, midi, ogg, png, svg, xcf, djvu. If the check is failed, then the user is prompted for a new filename.

Spaces in the filename will automatically be converted to underscores, since mediawiki doesn't allow spaces. The encoding of the filename will also be converted to the encoding used on the target site (typically unicode). The script also attempts to convert the description to the wiki's target encoding, or, as a last resort, will convert characters to html entities.

Error detection is based on both the http status and the contents of the response, which is assumed to be in English; error detection may fail if the bot's account has been set not to show an English interface.

Output example[edit | edit source]

Example of output if no file name is given:

C:\Users\t\Desktop\pywikipedia>upload.py
No input filename given
File or URL where image is now: C:\Users\t\Desktop\Dead7.jpg
Reading file C:\Users\t\Desktop\Dead7.jpg
The filename on the target wiki will default to: Dead7.jpg
Enter a better name, or press enter to accept:
The suggested description is:

Do you want to change this description? ([y]es, [N]o) n
Uploading file to dead:en via API....
Upload successful.

C:\Users\t\Desktop\pywikipedia>

Global arguments available for all bots

arg Description Default compat core
-dir:PATH Read the bot's configuration data from directory given by PATH, instead of from the default directory.
-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. user-config.py parameter: mylang
-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
-user:xyz Log in as user 'xyz' instead of the default username.
-daemonize:xyz Immediately return control to the terminal and redirect stdout and stderr to xyz (only use for bots that require no input from stdin).
-help Show a help text for the invoked script.
-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).
-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
-debug:item
-debug
Enable the logfile and include extensive debugging data for component "item" (for all components if the second form is used).
-putthrottle:nn
-pt:nn
Set the minimum time (in seconds) the bot will wait between saving pages. user-config.py parameter: put_throttle
-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


See also[edit | edit source]