tasks Package

tasks Package

class earwigbot.tasks.Task(bot)[source]

EarwigBot: Base Bot Task

This package provides built-in wiki bot “tasks” EarwigBot runs. Additional tasks can be installed as plugins in the bot’s working directory.

This class (import with from earwigbot.tasks import Task) can be subclassed to create custom bot tasks.

To run a task, use bot.tasks.start(name, **kwargs). **kwargs get passed to the Task’s run() method.

make_summary(comment)[source]

Make an edit summary by filling in variables in a config value.

config.wiki["summary"] is used, where $2 is replaced by the main summary body, given by the comment argument, and $1 is replaced by the task number.

If the config value is not found, we’ll just return comment as-is.

name = None
number = 0
run(**kwargs)[source]

Main entry point to run a given task.

This is called directly by tasks.start() and is the main way to make a task do stuff. kwargs will be any keyword arguments passed to start(), which are entirely optional.

setup()[source]

Hook called immediately after the task is loaded.

Does nothing by default; feel free to override.

shutoff_enabled(site=None)[source]

Return whether on-wiki shutoff is enabled for this task.

We check a certain page for certain content. This is determined by our config file: config.wiki["shutoff"]["page"] is used as the title, with any embedded $1 replaced by our username and $2 replaced by the task number; and config.wiki["shutoff"]["disabled"] is used as the content.

If the page has that exact content or the page does not exist, then shutoff is “disabled”, meaning the bot is supposed to run normally, and we return False. If the page’s content is something other than what we expect, shutoff is enabled, and we return True.

If a site is not provided, we’ll try to use self.site if it’s set. Otherwise, we’ll use our default site.

unload()[source]

Hook called immediately before the task is unloaded.

Does nothing by default; feel free to override.

wikiproject_tagger Module

class earwigbot.tasks.wikiproject_tagger.WikiProjectTagger(bot)[source]

Bases: earwigbot.tasks.Task

A task to tag talk pages with WikiProject banners.

Usage: earwigbot -t wikiproject_tagger PATH –banner BANNER (–category CAT | –file FILE) [–summary SUM] [–append TEXT] [–autoassess] [–nocreate] [–recursive NUM] [–site SITE]

--banner BANNER
the page name of the banner to add, without a namespace (unless the namespace is something other than Template) so --banner WikiProject Biography for {{WikiProject Biography}}
--category CAT or --file FILE
determines which pages to tag; either all pages in a category (to include subcategories as well, see --recursive) or all pages/categories in a file (utf-8 encoded and path relative to the current directory)
--summary SUM
an optional edit summary to use; defaults to "Adding WikiProject banner {{BANNER}}."
--append TEXT
optional text to append to the banner (after an autoassessment, if any), like |importance=low
--autoassess
try to assess each article’s class automatically based on the class of other banners on the same page
--nocreate
don’t create new talk pages with just a banner if the page doesn’t already exist
--recursive NUM
recursively go through subcategories up to a maximum depth of NUM, or if NUM isn’t provided, go infinitely (this can be dangerous)
--site SITE
the ID of the site to tag pages on, defaulting to the... default site
add_banner(code, banner)[source]

Add banner to code, following template order conventions.

apply_genfixes(code)[source]

Apply general fixes to code, such as template substitution.

get_banner_shell(code)[source]

Return the banner shell template within code, else None.

get_names(site, banner)[source]

Return all possible aliases for a given banner template.

guess_namespace(site, title, assumed)[source]

If the given title does not have an explicit namespace, guess it.

For example, when transcluding templates, the namespace is guessed to be NS_TEMPLATE unless one is explicitly declared (so {{foo}} -> [[Template:Foo]], but {{:foo}} -> [[Foo]]).

make_banner(job, code)[source]

Return banner text to add based on a job and a page’s code.

process_category(page, job, recursive)[source]

Try to tag all pages in the given category.

process_page(page, job)[source]

Try to tag a specific page using the job description.

run(**kwargs)[source]

Main entry point for the bot task.

run_job(kwargs, site, job, recursive)[source]

Run a tagging job on a given site.

Table Of Contents

Previous topic

irc Package

Next topic

wiki Package

This Page