A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. from json import loads
  3. from urllib import urlencode
  4. from urllib2 import urlopen
  5. from wiki.tools.category import Category
  6. from wiki.tools.page import Page
  7. from wiki.tools.user import User
  8. class Site(object):
  9. """
  10. EarwigBot's Wiki Toolset: Site Class
  11. """
  12. def __init__(self, name, project, lang, api=None, sql=(None, None)):
  13. """
  14. Docstring needed
  15. """
  16. self.name = name
  17. self.project = project
  18. self.lang = lang
  19. self.__api = api
  20. self.__sql = sql
  21. def api_query(self, params):
  22. """
  23. Docstring needed
  24. """
  25. params["format"] = "json"
  26. data = urlencode(params)
  27. result = urlopen(self.__api, data).read()
  28. return loads(result)
  29. def get_page(self, pagename):
  30. """
  31. Docstring needed
  32. """
  33. if pagename.startswith("Category:"): # proper namespace checking!
  34. return get_category(pagename[9:])
  35. return Page(self, pagename)
  36. def get_category(self, catname):
  37. """
  38. Docstring needed
  39. """
  40. return Category(self, "Category:" + catname) # namespace checking!
  41. def get_user(self, username):
  42. """
  43. Docstring needed
  44. """
  45. return User(self, username)