wikichangewatcher package

Submodules

wikichangewatcher.wikichangewatcher module

class wikichangewatcher.wikichangewatcher.FieldFilter[source]

Bases: object

Generic/abstract class for checking whether a specific field of the “recent changes” JSON event data matches some expected format/values.

The json_data provided to the on_match callback is an JSON-encoded event from the WikiMedia “recent changes” event stream, as described here: https://www.mediawiki.org/wiki/Manual:RCFeed

__init__()[source]
check_match(json_data: dict) bool[source]

Check if an edit event matches this filter

Parameters:

json_data – Edit event to check

Returns:

True if match

Return type:

bool

on_match(on_match_handler: Callable[[dict], None]) Self[source]

Set a function to be called when an edit event matching this filter is seen

Parameters:

on_match_handler – callback function

run_on_match(json_data: dict)[source]

Check if edit event matches this filter, and run on_match handler if it does match.

Parameters:

json_data – Edit event to check

class wikichangewatcher.wikichangewatcher.FieldRegexSearchFilter(fieldname: str, regex: str)[source]

Bases: FieldFilter

FieldFilter implementation to watch for a named field that contains one or more instances of the provided regular expression

__init__(fieldname: str, regex: str)[source]
class wikichangewatcher.wikichangewatcher.FilterCollection(*filters)[source]

Bases: FieldFilter

A Filter object that holds multiple filters, and can run a callback if all or any one of the filters matches

__init__(*filters)[source]
Parameters:

filters – one or more filter instances to use

set_match_type(match_type: int) Self[source]

Set match type for this collection. If MatchType.ALL, then this collection will match only if all contained filters match. If MatchType.ANY, then this collection will match if one of the contained filters match.

Match_type:

Match type, must be one of the values defined in wikichangewatcher.MatchType

class wikichangewatcher.wikichangewatcher.IpV4Filter(ip_addr_pattern='*.*.*.*')[source]

Bases: FieldFilter

FieldFilter implementation to watch for “user” fields that contain IPv4 addresses in the specified ranges

__init__(ip_addr_pattern='*.*.*.*')[source]

IPv4 address pattern to use. Each of the 4 dot-seperated fields may be one of the following:

  • A decimal integer from 0 through 255, representing exactly and only the written value.

  • A range of values in the form “0-255” (two decimal integers, both between 0 and 255, separated by a dash), representing any value between and including the two written values.

  • An asterisk ‘*’, representing any value from 0 through 255.

These can be used in combination. For example:

  • “*.*.*.*” matches any valid IPv4 address

  • “192.88.99.77” matches only one specific IPv4 address, 192.88.99.77

  • “192.88.0-9.*” matches 2,550 specific IPv4 addresses:

    192.88.0.0

    192.88.0.1

    192.88.0.2

    And so on, all the way up to 192.88.9.255

class wikichangewatcher.wikichangewatcher.IpV6Filter(ip_addr_pattern='*:*:*:*:*:*:*:*')[source]

Bases: FieldFilter

FieldFilter implementation to watch for “user” fields that contain IPv6 addresses in the specified ranges

__init__(ip_addr_pattern='*:*:*:*:*:*:*:*')[source]

IPv6 address pattern to use. Each of the 8 dot-seperated fields may be one of the following:

  • A hexadecimal integer from 0 through ffff, representing exactly and only the written value.

  • A range of values in the form “0-255” (two hexadecimal integers, both between 0 and ffff, separated by a dash), representing any value between and including the two written values.

  • An asterisk ‘*’, representing any value from 0 through ffff.

These can be used in combination. For example:

  • “*:*:*:*:*:*:*:*” matches any valid IPv6 address

  • “00.11.22.33.44.55.66.77” matches only one specific IPv6 address, 00.11.22.33.44.55.66.77

  • “00.11.22.33.44.55.0-9.*” matches 655,350 specific IPv6 addresses:

    00.11.22.33.44.55.0.0

    00.11.22.33.44.55.0.1

    00.11.22.33.44.55.0.2

    And so on, all the way up to 00.11.22.33.44.55.9.ffff

class wikichangewatcher.wikichangewatcher.MatchType[source]

Bases: object

Enumerates all match types handled by a FilterCollection

ALL = 0
ANY = 1
class wikichangewatcher.wikichangewatcher.PageUrlRegexSearchFilter(regex: str)[source]

Bases: FieldRegexSearchFilter

FieldRegexSearchFilter implementation to watch for a “title_url” field that contains one or more matches of a provided regular expression

__init__(regex: str)[source]
class wikichangewatcher.wikichangewatcher.UsernameRegexSearchFilter(regex: str)[source]

Bases: FieldRegexSearchFilter

FieldRegexSearchFilter implementation to watch for a “user” field that contains one or more matches of a provided regular expression

__init__(regex: str)[source]
class wikichangewatcher.wikichangewatcher.WikiChangeWatcher(*filters)[source]

Bases: object

Consumes all events from the Wikimedia “recent changes” stream, and applies all provided FieldFilter instances to each received event.

__init__(*filters)[source]
add_filter(fltr: Type[FieldFilter]) Self[source]

Add a new filter to the list of active filters

Parameters:

fltr – filter instance to add

is_running()[source]

Returns true if WikiChangeWatcher thread is active

Returns:

True if thread is active

Return type:

bool

on_edit(on_edit_handler: Callable[[dict], None]) Self[source]

Sets handler to run whenever any edit event is received (before any filters are processed)

Parameters:

on_edit_handler – Handler to run on edit event

run()[source]

Start WikiChangeWatcher running in a separate thread

set_ignore_log_events(ignore: bool) Self[source]

Set whether log events will be ignored (default if unset is True).

Parameters:

ignore – True to ignore log events, False to ignore nothing.

stop()[source]

Send stop event to the running WikiWatcher thread and wait for it to terminate

Module contents