A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

page.py 851 B

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding: utf-8 -*-
  2. class Page(object):
  3. """
  4. EarwigBot's Wiki Toolset: Page Class
  5. """
  6. def __init__(self, site, title):
  7. """
  8. Docstring needed
  9. """
  10. self.site = site
  11. self.title = title
  12. self._content = None
  13. def exists(self):
  14. """
  15. Docstring needed
  16. """
  17. pass
  18. def get(self, force_reload=False):
  19. """
  20. Docstring needed
  21. """
  22. if self._content is None or force_reload:
  23. params = {"action": "query", "prop": "revisions",
  24. "rvprop": "content", "rvlimit": 1, "titles": self.title}
  25. result = self.site.api_query(params)
  26. content = result["query"]["pages"].values()[0]["revisions"][0]["*"]
  27. self._content = content
  28. return content
  29. return self._content