A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

README.rst 9.4 KiB

12 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. EarwigBot
  2. =========
  3. EarwigBot_ is a Python_ robot that edits Wikipedia_ and interacts with people
  4. over IRC_. This file provides a basic overview of how to install and setup the
  5. bot; more detailed information is located in the ``docs/`` directory (available
  6. online at PyPI_).
  7. History
  8. -------
  9. Development began, based on the `Pywikipedia framework`_, in early 2009.
  10. Approval for its fist task, a `copyright violation detector`_, was carried out
  11. in May, and the bot has been running consistently ever since (with the
  12. exception of Jan/Feb 2011). It currently handles `several ongoing tasks`_
  13. ranging from statistics generation to category cleanup, and on-demand tasks
  14. such as WikiProject template tagging. Since it started running, the bot has
  15. made over 50,000 edits.
  16. A project to rewrite it from scratch began in early April 2011, thus moving
  17. away from the Pywikipedia framework and allowing for less overall code, better
  18. integration between bot parts, and easier maintenance.
  19. Installation
  20. ------------
  21. This package contains the core ``earwigbot``, abstracted enough that it should
  22. be usable and customizable by anyone running a bot on a MediaWiki site. Since
  23. it is component-based, the IRC components can be disabled if desired. IRC
  24. commands and bot tasks specific to `my instance of EarwigBot`_ that I don't
  25. feel the average user will need are available from the repository
  26. `earwigbot-plugins`_.
  27. It's recommended to run the bot's unit tests before installing. Run ``python
  28. setup.py test`` from the project's root directory. Note that some
  29. tests require an internet connection, and others may take a while to run.
  30. Coverage is currently rather incomplete.
  31. Latest release (v0.1)
  32. ~~~~~~~~~~~~~~~~~~~~~
  33. EarwigBot is available from the `Python Package Index`_, so you can install the
  34. latest release with ``pip install earwigbot`` (`get pip`_).
  35. You can also install it from source [1]_ directly::
  36. curl -Lo earwigbot.tgz https://github.com/earwig/earwigbot/tarball/v0.1
  37. tar -xf earwigbot.tgz
  38. cd earwig-earwigbot-*
  39. python setup.py install
  40. cd ..
  41. rm -r earwigbot.tgz earwig-earwigbot-*
  42. Development version
  43. ~~~~~~~~~~~~~~~~~~~
  44. You can install the development version of the bot from ``git`` by using
  45. setuptools/distribute's ``develop`` command [1]_, probably on the ``develop``
  46. branch which contains (usually) working code. ``master`` contains the latest
  47. release. EarwigBot uses `git flow`_, so you're free to
  48. browse by tags or by new features (``feature/*`` branches)::
  49. git clone git://github.com/earwig/earwigbot.git earwigbot
  50. cd earwigbot
  51. python setup.py develop
  52. Setup
  53. -----
  54. The bot stores its data in a "working directory", including its config file and
  55. databases. This is also the location where you will place custom IRC commands
  56. and bot tasks, which will be explained later. It doesn't matter where this
  57. directory is, as long as the bot can write to it.
  58. Start the bot with ``earwigbot path/to/working/dir``, or just ``earwigbot`` if
  59. the working directory is the current directory. It will notice that no
  60. ``config.yml`` file exists and take you through the setup process.
  61. There is currently no way to edit the ``config.yml`` file from within the bot
  62. after it has been created, but YAML is a very straightforward format, so you
  63. should be able to make any necessary changes yourself. Check out the
  64. `explanation of YAML`_ on Wikipedia for help.
  65. After setup, the bot will start. This means it will connect to the IRC servers
  66. it has been configured for, schedule bot tasks to run at specific times, and
  67. then wait for instructions (as commands on IRC). For a list of commands, say
  68. "``!help``" (commands are messages prefixed with an exclamation mark).
  69. You can stop the bot at any time with Control+C, same as you stop a normal
  70. Python program, and it will try to exit safely. You can also use the
  71. "``!quit``" command on IRC.
  72. Customizing
  73. -----------
  74. The bot's working directory contains a ``commands`` subdirectory and a
  75. ``tasks`` subdirectory. Custom IRC commands can be placed in the former,
  76. whereas custom wiki bot tasks go into the latter. Developing custom modules is
  77. explained below, and in more detail through the bot's documentation on PyPI_
  78. (or in the ``docs/`` dir).
  79. Note that custom commands will override built-in commands and tasks with the
  80. same name.
  81. ``Bot`` and ``BotConfig``
  82. ~~~~~~~~~~~~~~~~~~~~~~~~~
  83. `earwigbot.bot.Bot`_ is EarwigBot's main class. You don't have to instantiate
  84. this yourself, but it's good to be familiar with its attributes and methods,
  85. because it is the main way to communicate with other parts of the bot. A
  86. ``Bot`` object is accessible as an attribute of commands and tasks (i.e.,
  87. ``self.bot``).
  88. `earwigbot.config.BotConfig`_ stores configuration information for the bot. Its
  89. docstring explains what each attribute is used for, but essentially each "node"
  90. (one of ``config.components``, ``wiki``, ``irc``, ``commands``, ``tasks``, and
  91. ``metadata``) maps to a section of the bot's ``config.yml`` file. For example,
  92. if ``config.yml`` includes something like::
  93. irc:
  94. frontend:
  95. nick: MyAwesomeBot
  96. channels:
  97. - "##earwigbot"
  98. - "#channel"
  99. - "#other-channel"
  100. ...then ``config.irc["frontend"]["nick"]`` will be ``"MyAwesomeBot"`` and
  101. ``config.irc["frontend"]["channels"]`` will be ``["##earwigbot", "#channel",
  102. "#other-channel"]``.
  103. Custom IRC commands
  104. ~~~~~~~~~~~~~~~~~~~
  105. Custom commands are subclasses of `earwigbot.commands.Command`_ that override
  106. ``Command``'s ``process()`` (and optionally ``check()``, ``setup()``, or
  107. ``unload()``) methods.
  108. The bot has a wide selection of built-in commands and plugins to act as sample
  109. code and/or to give ideas. Start with test_, and then check out chanops_ and
  110. afc_status_ for some more complicated scripts.
  111. Custom bot tasks
  112. ~~~~~~~~~~~~~~~~
  113. Custom tasks are subclasses of `earwigbot.tasks.Task`_ that override ``Task``'s
  114. ``run()`` (and optionally ``setup()`` or ``unload()``) methods.
  115. See the built-in wikiproject_tagger_ task for a relatively straightforward
  116. task, or the afc_statistics_ plugin for a more complicated one.
  117. The Wiki Toolset
  118. ----------------
  119. EarwigBot's answer to the `Pywikipedia framework`_ is the Wiki Toolset
  120. (``earwigbot.wiki``), which you will mainly access through ``bot.wiki``.
  121. ``bot.wiki`` provides three methods for the management of Sites -
  122. ``get_site()``, ``add_site()``, and ``remove_site()``. Sites are objects that
  123. simply represent a MediaWiki site. A single instance of EarwigBot (i.e. a
  124. single *working directory*) is expected to relate to a single site or group of
  125. sites using the same login info (like all WMF wikis with CentralAuth).
  126. Load your default site (the one that you picked during setup) with
  127. ``site = bot.wiki.get_site()``.
  128. Not all aspects of the toolset are covered in the docs. Explore `its code and
  129. docstrings`_ to learn how to use it in a more hands-on fashion. For reference,
  130. ``bot.wiki`` is an instance of ``earwigbot.wiki.SitesDB`` tied to the
  131. ``sites.db`` file in the bot's working directory.
  132. Footnotes
  133. ---------
  134. - Questions, comments, or suggestions about the documentation? `Let me know`_
  135. so I can improve it for other people.
  136. .. [1] ``python setup.py install``/``develop`` may require root, or use the
  137. ``--user`` switch to install for the current user only.
  138. .. _EarwigBot: http://en.wikipedia.org/wiki/User:EarwigBot
  139. .. _Python: http://python.org/
  140. .. _Wikipedia: http://en.wikipedia.org/
  141. .. _IRC: http://en.wikipedia.org/wiki/Internet_Relay_Chat
  142. .. _PyPI: http://packages.python.org/earwigbot
  143. .. _Pywikipedia framework: http://pywikipediabot.sourceforge.net/
  144. .. _copyright violation detector: http://en.wikipedia.org/wiki/Wikipedia:Bots/Requests_for_approval/EarwigBot_1
  145. .. _several ongoing tasks: http://en.wikipedia.org/wiki/User:EarwigBot#Tasks
  146. .. _my instance of EarwigBot: http://en.wikipedia.org/wiki/User:EarwigBot
  147. .. _earwigbot-plugins: https://github.com/earwig/earwigbot-plugins
  148. .. _Python Package Index: https://pypi.python.org/pypi/earwigbot
  149. .. _get pip: http://pypi.python.org/pypi/pip
  150. .. _git flow: http://nvie.com/posts/a-successful-git-branching-model/
  151. .. _explanation of YAML: http://en.wikipedia.org/wiki/YAML
  152. .. _earwigbot.bot.Bot: https://github.com/earwig/earwigbot/blob/develop/earwigbot/bot.py
  153. .. _earwigbot.config.BotConfig: https://github.com/earwig/earwigbot/blob/develop/earwigbot/config.py
  154. .. _earwigbot.commands.Command: https://github.com/earwig/earwigbot/blob/develop/earwigbot/commands/__init__.py
  155. .. _test: https://github.com/earwig/earwigbot/blob/develop/earwigbot/commands/test.py
  156. .. _chanops: https://github.com/earwig/earwigbot/blob/develop/earwigbot/commands/chanops.py
  157. .. _afc_status: https://github.com/earwig/earwigbot-plugins/blob/develop/commands/afc_status.py
  158. .. _earwigbot.tasks.Task: https://github.com/earwig/earwigbot/blob/develop/earwigbot/tasks/__init__.py
  159. .. _wikiproject_tagger: https://github.com/earwig/earwigbot/blob/develop/earwigbot/tasks/wikiproject_tagger.py
  160. .. _afc_statistics: https://github.com/earwig/earwigbot-plugins/blob/develop/tasks/afc_statistics.py
  161. .. _its code and docstrings: https://github.com/earwig/earwigbot/tree/develop/earwigbot/wiki
  162. .. _Let me know: ben.kurtovic@gmail.com