A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. from wiki.tools.page import Page
  3. class Category(Page):
  4. """
  5. EarwigBot's Wiki Toolset: Category Class
  6. Represents a Category on a given Site, a subclass of Page. Provides
  7. additional methods, but Page's own methods should work fine on Category
  8. objects. Site.get_page() will return a Category instead of a Page if the
  9. given title is in the category namespace; get_category() is shorthand,
  10. because it accepts category names without the namespace prefix.
  11. Public methods:
  12. members -- returns a list of titles in the category
  13. """
  14. def members(self, limit=50):
  15. """Returns a list of titles in the category.
  16. If `limit` is provided, we will provide this many titles, or less if
  17. the category is too small. `limit` defaults to 50; normal users can go
  18. up to 500, and bots can go up to 5,000 on a single API query.
  19. """
  20. params = {"action": "query", "list": "categorymembers",
  21. "cmlimit": limit, "cmtitle": self.title}
  22. result = self._site._api_query(params)
  23. members = result['query']['categorymembers']
  24. return [member["title"] for member in members]