Manual:Pywikibot/upload.py
File:Git icon.svg | <translate> Wikimedia [[<tvar|1>Special:MyLanguage/Gerrit</>|Git repository]] has this file:</translate> scripts/upload.py |
File:Pywikibot MW gear icon.svg |
<translate> Pywikibot scripts</translate> |
---|
|
· <span style="" title="<translate nowrap> Edit this template</translate>"><translate> e</translate> |
upload.py is a Pywikibot script used to upload images to a wiki.
Usage
$ python3 pwb.py upload [Global-arguments] [-keep] [-filename:targetFilename] [-ignorewarn] [-noverify] [-chunked:64m] [-summary:SummaryOfTheUpload] [URL-or-filename] [-descfile:description-file]
Arguments
-keep | Keep the filename as is |
-filename | Target filename |
-recursive | A recursive search in folders ? |
-noverify | Do not ask for verification of the upload description if one is given Not proofread the description |
-summary | Summary of the upload (-summary:"MySummary" )
|
-ignorewarn | Upload even if another file would be overwritten or another mistake would be risked |
-chunked | Upload the file in chunks (more overhead, but restartable) ; If no value is specified the file will be uploaded as whole ; regex : ^-chunked(?::(\d+(?:\.\d+)?)[ \t]*(k|ki|m|mi)?b?)?$
|
-always | Save without confirmation ; Enable keepFilename and disable verifyDescription |
-abortonwarn | ... |
-descfile | Path to filename where the description is stored |
If any other arguments are given, the first is the URL, directory, 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, directory, 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, pdf. If the check is failed, then the user is prompted for a new filename.
If an image with the target filename already exists, the description will not be overwritten with the supplied description text. Instead, the description text will be added as a comment.
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.
Note: Very large files that are uploaded to Wikimedia Commons: are best uploaded with the chunked parameter. — billinghurst sDrewth 13:19, 22 January 2020 (UTC)
Output example
Example of output if no file name is given:
C:\Users\t\Desktop\pywikibot>pwb.py upload
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\pywikibot>
Examples
python /mnt/nfs/labstore-secondary-tools-home/wmr-bot/core/pwb.py upload "pdf/000787-周易兼義九卷十三經註疏所收-卷首.pdf" -filename:"IOC.UTokyo-000787 周易兼義九卷十三經註疏所收 卷首.pdf" -ignorewarn -chunked -noverify -descfile:des/0 -always
Where des/0 is the path of a file indicating the description of the file.
python3 pwb.py upload /home/username/Logo/Ready "logo images" -keep -noverify -ignorewarn -summary:"Bot: Uploading logo images"
Note that the first parameter after 'upload' is the local image directory (spaces in the name must be escaped with a backslash(\) ); the second parameter is the upload description surrounded by double quotes; the three parameters after that are needed for batch uploads.
<translate> Global arguments available</translate>
<translate> This page is outdated.</translate> |
<translate> These options will override the configuration in <tvar|1>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> | |
-config:<translate> file</translate> |
<translate> The user config filename.</translate> Default is user-config.py. | user-config.py |
-configfile>user-config.py</>. <tvar |
xx>xx</> should be the language code.</translate> | mylang |
-configfile>user-config.py</>.</translate> |
<translate> Set the family of the wiki you want to work on, e.g. wikipedia, wiktionary, wikitravel, ...</translate> <translate> This will override the configuration in <tvar | family |
-xyz>xyz</>' instead of the default username.</translate> |
<translate> Log in as user '<tvar | usernames |
-xyz>xyz</>. (only use for bots that require no input from stdin).</translate> |
<translate> Immediately return control to the terminal and redirect stdout and stderr to file <tvar | |
-help |
<translate> Show the help text.</translate> | |
-1>-bot.log</>' Logs will be stored in the logs subdirectory.</translate> |
<translate> Enable the log file, using the default filename 'script_name<tvar | log |
-xyz>xyz</>' as the filename.</translate> |
<translate> Enable the log file, using '<tvar | logfilename |
-nolog |
<translate> Disable the log file (if it is enabled by default).</translate> | |
-1>config.py</></translate> |
<translate> Sets a new maxlag parameter to a number of seconds.</translate> <translate> Defer bot edits during periods of database server lag. Default is set by <tvar | 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 |
-cosmetic>cosmetic_changes</> setting made in <tvar -cc |
config>config.py</> or <tvar | cosmetic_changes |
-simulate |
<translate> Disables writing to the server.</translate> <translate> 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> |