- Notifications
You must be signed in to change notification settings - Fork0
A Python library that interfaces with the MediaWiki API. This is a mirror from gerrit.wikimedia.org. Seehttps://www.mediawiki.org/wiki/Developer_access for contributing.
License
ninjastrikers/pywikibot
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The Pywikibot framework is a Python library that interfaces with theMediaWiki APIversion 1.27 or higher.
Also included are various general function scripts that can be adapted fordifferent tasks.
For further information about the library excluding scripts seethe fullcode documentation.
git clone https://gerrit.wikimedia.org/r/pywikibot/core.gitcd coregit submodule update --initpip install -r requirements.txtpython pwb.py <script_name>
Or to install using PyPI (excluding scripts)
pip install pywikibotpwb <scriptname>
Ourinstallationguidehas more details for advanced usage.
If you wish to write your own script it's very easy to get started:
importpywikibotsite=pywikibot.Site('en','wikipedia')# The site we want to run our bot onpage=pywikibot.Page(site,'Wikipedia:Sandbox')page.text=page.text.replace('foo','bar')page.save('Replacing "foo" with "bar"')# Saves the page
Wikibase is a flexible knowledge base software that drives Wikidata.A sample pywikibot script for getting data from Wikibase:
importpywikibotsite=pywikibot.Site('wikipedia:en')repo=site.data_repository()# the Wikibase repository for given sitepage=repo.page_from_repository('Q91')# create a local page for the given itemitem=pywikibot.ItemPage(repo,'Q91')# a repository itemdata=item.get()# get all item data from repository for this item
Pywikibot provides bot classes to develop your own script easily:
importpywikibotfrompywikibotimportpagegeneratorsfrompywikibot.botimportExistingPageBotclassMyBot(ExistingPageBot):update_options= {'text':'This is a test text','summary':'Bot: a bot test edit with Pywikibot.' }deftreat_page(self):"""Load the given page, do some changes, and save it."""text=self.current_page.texttext+='\n'+self.opt.textself.put_current(text,summary=self.opt.summary)defmain():"""Parse command line arguments and invoke bot."""options= {}gen_factory=pagegenerators.GeneratorFactory()# Option parsinglocal_args=pywikibot.handle_args(args)# global optionslocal_args=gen_factory.handle_args(local_args)# generators optionsforarginlocal_args:opt,sep,value=arg.partition(':')ifoptin ('-summary','-text'):options[opt[1:]]=valueMyBot(generator=gen_factory.getCombinedGenerator(),**options).run()if__name=='__main__':main()
For more documentation on Pywikibot see ourdocs.
Seehttps://github.com/wikimedia/pywikibot/blob/stable/HISTORY.rst
Our code is maintained on Wikimedia'sGerrit installation,learn how to getstarted.
About
A Python library that interfaces with the MediaWiki API. This is a mirror from gerrit.wikimedia.org. Seehttps://www.mediawiki.org/wiki/Developer_access for contributing.
Resources
License
Stars
Watchers
Forks
Packages0
Languages
- Python100.0%