User:Fæ/code/Pywikibot command line

From Wikimedia Commons, the free media repository
< User:Fæ‎ | code
Jump to navigation Jump to search

As well as being useful for coding bot tasks and specialized housekeeping jobs, Pywikibot can be run from a terminal command line. Sometimes this can be be more efficient that using a tool like Help:VFC, especially when several thousand files need processing rather than a couple of hundred.

Pywikibot-core uses "python pwb.py <command>" rather than running the command directly.

Snippets

[edit]

It is recommended you adapt these, do not just run them without being aware of what might happen!

Mark all files in a category for speedy deletion using a bot account

[edit]
python pwb.py replace.py -cat:"Uploads by Fæ needing speedy deletion" -regex -dotall "^(.)" "{{speedy|Uploader request based on being non-contenious potential copyvio or out of scope.}}\n\1" -summary:"Uploader requested or agreed speedy" -ns:6 -dir:faebot

Adapt all PD-UKGov licenses for files in a category to use PD-Scan

[edit]
python replace.py -cat:"Imperial War Museum First World War Women's War Work Collection" -regex -dotall "\n\{\{PD-UKGov\}\}" "\n{{PD-Scan|1=PD-UKGov|category=}}" -ns:6 -summary:"Add {{PD-Scan}}"

Harmonize the format of a user category for files uploaded using Magnus' File Upload Bot

[edit]
python replace.py -cat:"Flickr images uploaded by Flickr upload bot"  -regex -dotall "([Uu]pload.*?MaybeMaybeMaybe.*)" "\1\n[[Category:Uploads by MaybeMaybeMaybe]]" "(..[Cc]ategory:Uploads[ _]by[ _]MaybeMaybeMaybe...*)\n\[\[[Cc]ategory:[Uu]ploads by MaybeMaybeMaybe\]\]" "\1" "\[\[[Cc]ategory:Uploads_by_MaybeMaybeMaybe\]\]" "[[Category:Uploads by MaybeMaybeMaybe]]" -summary:"Add [[Category:Uploads by MaybeMaybeMaybe]]" -ns:6

Remove category from files in another category

[edit]
python replace.py -cat:"Waters' Edge Park" -regex "\[\[[cC]ategory:Barton-upon-Humber\]\]\n?" "" -summary:"Trim as Barton-upon-Humber is a parent category of Water's Edge Park"