Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

NotificationsYou must be signed in to change notification settings

ninjastrikers/pywikibot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub CICode coverageMaintainabilityPythonTop languagePywikibot releasewheelTotal downloadsMonthly downloadsLast commit

Pywikibot

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.

Quick start

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.

Basic 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 Usage

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

Script example

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.

Roadmap

Release history

Seehttps://github.com/wikimedia/pywikibot/blob/stable/HISTORY.rst

Contributing

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

Packages

No packages published

Languages

  • Python100.0%

[8]ページ先頭

©2009-2025 Movatter.jp