-
Notifications
You must be signed in to change notification settings - Fork 78
Usage
Steve edited this page Sep 22, 2017
·
32 revisions
Simply import wptools to get started.
>>> import wptoolsThe simplest way to begin is with a title:
>>> flannery = wptools.page("Flannery O'Connor")
Flannery_O'Connor (en)
{
lang: en
title: Flannery_O'Connor
}The default language is 'en' (English):
>>> toshiko = wptools.page('穐吉敏子')
穐吉敏子 (en)
{
lang: en
title: 穐吉敏子
}If you specify only lang, you get a random article in that language:
>>> tubman = wptools.page(lang='zh')
zh.wikipedia.org (random) 🍰
哈莉特·塔布曼 (zh)
{
lang: zh
pageid: 211070
title: 哈莉特·塔布曼
}Leaving off arguments invokes a random lookup in English:
>>> page = wptools.page()
en.wikipedia.org (random) 🍜
Sylvia_Rivera (en)
{
lang: en
pageid: 3296309
title: Sylvia_Rivera
}You can also start with a wikibase item:
>>> malcolmx = wptools.page(wikibase='Q43303')
Q43303 (en)
{
lang: en
wikibase: Q43303
}Or, another wiki site:
>>> page = wptools.page(wiki='en.wikiquote.org')
en.wikiquote.org (random) 🍪
Malala_Yousafzai (en)
{
lang: en
pageid: 146817
title: Malala_Yousafzai
wiki: en.wikiquote.org
}Object data echoes automatically. You can turn that off with silent=True:
>>> page = wptools.page(silent=True)HTTP request/response details echo to stderr with verbose=True:
>>> page = wptools.page(verbose=True)All request actions support setting proxy and timeout (in seconds):
>>> page.get(proxy='http://example.com:80', timeout=5)You can skip request actions using skip:
>>> page = wptools.page(skip=['claims', 'imageinfo'])Calling wptools.category() with no arguments envokes a random cateogory lookup.
>>> cat = wptools.category()
en.wikipedia.org (random:14) 🍕
Category:Jazz Messengers (en) data
{
pageid: 44375025
title: Category:Jazz Messengers
}Get category members with get_members():
>>> cat.get_members()
en.wikipedia.org (categorymembers) Category:Jazz Messengers
Category:Jazz Messengers (en) data
{
members: <list(56)> {u'ns': 0, u'pageid': 43686772, u'title': u'...
}