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ů.

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