Instantly share code, notes, and snippets.

Embed
What would you like to do?
Count all pages within a category and its sub-categories recursively
# -*- coding: utf-8 -*-
"""
Description
Count all pages within a category and its sub-categories recursively
Modifying Junaid's code with a Tamil Wiki example.
@author Junaid, Sundar
"""
import wikipedia
import catlib
wiki = 'wikipedia'
lang = 'ta'
cat_title = ur'பகுப்பு:சூழியல்'
site = wikipedia.Site(code=lang, fam=wiki)
cat = catlib.Category(site=site, title=cat_title)
count = len(cat.articlesList(recurse=True))
print "Number of articles in the category: ", count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment