User:AWB Alex/Pywikibot

From Guild Wars 2 Wiki
Jump to navigationJump to search

Pywikibot is a command line based python script that is capable of making repetitive edits, similar to the capabilities of AutoWikiBrowser, but Pywikibot is notable since page actions such as delete and restore are also available for automation.

Since Pywikibot was designed with the intention of editing the core wikipedia projects, and are mainly intended to be run from the server, some modifications to the script are required to use the script from a windows command line on a third-party wiki.

External reference[edit]

Useful stuff[edit]

Setup[edit]

Prelude
[0] Download python from "https://www.python.org/downloads/"
[1] Right click the installation wizard and run as admin. Accept the default location if you're not actively looking for trouble.
[2] Download pywikibot, it's a small zip file with about 5700 files.
[3] Unzip it to the right location (your choice). Mine was "G:\Downloads\Utilities\Pywikibot"
Wiki setup
[4] Open windows command prompt. Run the following line to change the target. Or shift-right click whilst in windows explorer.
 cd /d "G:\Downloads\Utilities\Pywikibot"
[5] Run the following script (this uses pip.exe, installed with python, to download all the external libraries). Expect it to throw an error when it gets to oursql egg_info. Ignore it and move to step 6.
 pip install -r requirements
[6] Run the following script to fail to login and create your setup files. Follow the prompts.
 pwb.py login
Family settings: url = https://wiki.guildwars2.com/wiki/Main_Page, name = gw2w
User settings: name = AWB Alex
[7] Try run the login script again, this time giving it your bot account's regular password when prompted. It should throw some deprecated token warnings.
[8] Open your "user-config.py" file in notepad++, add the following line beneath your username
 password_file = 'botpasswordfile.txt'
[9] Create a new textfile called "botpasswordfile.txt" in the same folder as "user-config.py" with the following contents
 ("en", "gw2w", "AWB Alex", "MYPASSWORDGOESHERE")

work in progress.

Scripts of interest[edit]

Deleting pages[edit]

cd /d "G:\Downloads\Utilities\Pywikibot"
pwb.py delete.py -file:deletion_list.txt -always -summary:"Redundant image"
  • delete.py used with the undelete flag:
cd /d "G:\Downloads\Utilities\Pywikibot"
pwb.py delete.py -undelete -file:deletion_list.txt -always -summary:"SMW Blank and restore"
Contents of "file_deletion.txt"
# [[User:AWB Alex/sandbox]]

Moving pages[edit]

cd /d "G:\Downloads\Utilities\Pywikibot"
python movepages.py -pairs:"article_pairs.txt" -noredirect -always -summary:"Renaming skin armor gallery files"
Contents of "article_pairs.txt"
[[from page]]
[[to page]]
[[from page]]
[[to page]]


Single file upload[edit]

cd /d "G:\Downloads\Utilities\Pywikibot"
python upload.py -keep -noverify -filename:"wikifilename.png" "uploadfolder\wikifilename.png" "{{ArenaNet image|icon|Trophy icons}}"

Multiple file upload[edit]

  • No working script to do multiple files on mediawiki. Thus we have no choice but to use upload.py in a bat file.

Generate this by running a DOS sequence to list the files

cd /d "G:\Downloads\Utilities\Pywikibot\uploadfolder"
dir /w > uploadlist.txt

Run the results through the following wikitext to highlight new files

{{#arraymap:
...
|\n|@@@|*{{ifimage|@@@|@@@ [already exists]|@@@}}|\n}}

Bookmark lines with "[already exists]", then remove them. Voila, you now have an updated list with only new files.

Then edit the file with nodepad++:

FIND:
(.*)
REPLACE WITH:
python upload.py -keep -noverify -filename:"$1" "uploadfolder\\$1" "{{ArenaNet image\|icon\|Trophy icons}}"

Add

cd /d "G:\Downloads\Utilities\Pywikibot"

to the top. Then rename the file to uploadlist.bat

cd /d "G:\Downloads\Utilities\Pywikibot"
uploadlist.bat