-
Notifications
You must be signed in to change notification settings - Fork 51
category.Category
Category objects are a subclass of Page objects, with a few extra functions specific to categories.
The constructor for Category is identical to Page, minus the namespace
option. If no "Category:" prefix is in the title, it will be added automatically.
Most of the methods of the Category class are the same as in Page, with a few additional ones.
getCategoryInfo(force=False)
Returns a dict with some basic information about the category: the total number of items in the category, the number of ordinary pages, the number of files, and the number of subcategories. After retrieving, it will be cached in the object. To override and get it from the server again, set force
to True.
getAllMembers(titleonly=False, namespaces=None)
Gets all of the items in the category in a list. By default it will return Page objects. If you only want the titles, set titleonly
to True. Can be limited to namespaces
by passing an array of Namespaces or integer namespace numbers.
getAllMembersGen(titleonly=False, namespaces=None)
Has the same options as getAllMembers, except it works as a generator function, retrieving a few results at a time and yielding individual Pages or titles.
-
__getMembersInternal()
- Does the API queries for getAllMembers/getAllMembersGen
Category has the same instance variables as Page, with one additional variable.
-
info
- Contains the data from getCategoryInfo
Get information about a category and get the members
from wikitools import wiki, category
site = wiki.Wiki("https://www.mediawiki.org/w/api.php")
c = category.Category(site, "Category:Wiki markup")
print(str( c.getCategoryInfo() ))
for p in c.getAllMembersGen():
print(p.title)
will output
{'subcats': 0, 'pages': 6, 'files': 0, 'size': 6}
Manual:CSS
Manual:MediaWiki Developer's Guide
Manual:ISBN
Manual:Parser functions
Manual:RFC
UNC links