A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

category.py 1.2 KiB

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. from wiki.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]