User:Geertivp/Training/Pywikibot/Install
Appearance
pywikibot is a well-known Python Wiki bot.
It can be used with Wikimedia projects, as well as on a private Mediawiki server.
Here we will document how to use it on Wikimedia projects.
Prerequisites
[edit]pip install requests
But this is already installed on a Mediawiki server.
Install
[edit]wget http://tools.wmflabs.org/pywikibot/core.tar.gz
Now restore it in a user account:
tar -xf core.tar.gz
mv core pywikibot
Configure
[edit]cd pywikibot
python pwb.py generate_user_files
vi user-config.py
password_file = 'user-password.py'
user_script_paths = ['scripts.userscripts']
touch user-password.py chmod 600 user-password.py vi user-password.py
( 'User', 'password' )
Test your setup
[edit]Test your login account:
python pwb.py login
Show user page:
python pwb.py shell
site = pywikibot.Site()
page = pywikibot.Page(site, u'User:Geertivp')
print page
text=page.text
print text
User script
[edit]cp scripts/basic.py scripts/userscripts/getuserpage.py
vi scripts/userscripts/getuserpage.py
def main(*args):
site = pywikibot.Site()
page = pywikibot.Page(site, u'User:Geertivp')
print page
text=page.text
print text
python pwb.py getuserpage
Create a page
[edit]python pwb.py shell
import pywikibot site = pywikibot.Site() page = pywikibot.Page(site, u'User:Geertivp/Pywikibot test') print page text=page.text print text page.text=u'Pywikibot test' page.save(u'Pywikibot test')