_watchers
_watchers
¶
Polling watchers that detect changes and produce events.
BaseWatcher
¶
BaseWatcher(
api: CocApi,
state: PollingState,
queue: Queue[Event],
interval: float,
)
Base class for all watchers.
Subclasses implement _poll_once() which fetches data, diffs it,
and returns a list of events.
Initialize the watcher.
| PARAMETER | DESCRIPTION |
|---|---|
api
|
CocApi instance in async mode.
TYPE:
|
state
|
Shared polling state for snapshot storage.
TYPE:
|
queue
|
Event queue to push detected changes to.
TYPE:
|
interval
|
Seconds between poll cycles.
TYPE:
|
Source code in cocapi/events/_watchers.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
start
¶
start() -> None
Start the polling loop as an asyncio task.
Source code in cocapi/events/_watchers.py
80 81 82 83 84 85 | |
stop
async
¶
stop() -> None
Stop the polling loop and cancel the background task.
Source code in cocapi/events/_watchers.py
87 88 89 90 91 92 93 94 95 96 | |
ClanWatcher
¶
ClanWatcher(
api: CocApi,
state: PollingState,
queue: Queue[Event],
clan_tags: list[str],
interval: float = 60.0,
track_members: bool = True,
)
Bases: BaseWatcher
Polls clan data and member lists.
Initialize the clan watcher.
| PARAMETER | DESCRIPTION |
|---|---|
api
|
CocApi instance in async mode.
TYPE:
|
state
|
Shared polling state.
TYPE:
|
queue
|
Event queue for detected changes.
TYPE:
|
clan_tags
|
Clan tags to poll.
TYPE:
|
interval
|
Seconds between polls (default 60).
TYPE:
|
track_members
|
Whether to track member join/leave/update events.
TYPE:
|
Source code in cocapi/events/_watchers.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
WarWatcher
¶
WarWatcher(
api: CocApi,
state: PollingState,
queue: Queue[Event],
clan_tags: list[str],
interval: float = 30.0,
)
Bases: BaseWatcher
Polls current war and tracks state transitions and new attacks.
Initialize the war watcher.
| PARAMETER | DESCRIPTION |
|---|---|
api
|
CocApi instance in async mode.
TYPE:
|
state
|
Shared polling state.
TYPE:
|
queue
|
Event queue for detected changes.
TYPE:
|
clan_tags
|
Clan tags to watch for war updates.
TYPE:
|
interval
|
Seconds between polls (default 30).
TYPE:
|
Source code in cocapi/events/_watchers.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
PlayerWatcher
¶
PlayerWatcher(
api: CocApi,
state: PollingState,
queue: Queue[Event],
player_tags: list[str],
interval: float = 120.0,
include_fields: frozenset[str] | None = None,
exclude_fields: frozenset[str] | None = None,
)
Bases: BaseWatcher
Polls player data and detects field changes.
Emits granular events for upgrades (troops, spells, heroes, equipment,
townhall, builder hall) as well as the generic PLAYER_UPDATED event
for any other top-level field change.
Initialize the player watcher.
| PARAMETER | DESCRIPTION |
|---|---|
api
|
CocApi instance in async mode.
TYPE:
|
state
|
Shared polling state.
TYPE:
|
queue
|
Event queue for detected changes.
TYPE:
|
player_tags
|
Player tags to poll.
TYPE:
|
interval
|
Seconds between polls (default 120).
TYPE:
|
include_fields
|
Only report changes to these fields.
TYPE:
|
exclude_fields
|
Ignore changes to these fields.
TYPE:
|
Source code in cocapi/events/_watchers.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
MaintenanceWatcher
¶
MaintenanceWatcher(
api: CocApi,
state: PollingState,
queue: Queue[Event],
interval: float = 30.0,
probe_tag: str = "#JY9J2Y99",
)
Bases: BaseWatcher
Detects API maintenance windows by polling a known endpoint.
Emits MAINTENANCE_START when the API starts returning errors
(HTTP 503 or connection failures) and MAINTENANCE_END when it
recovers. Uses a configurable probe tag (defaults to a well-known
player #JY9J2Y99).
Initialize the maintenance watcher.
| PARAMETER | DESCRIPTION |
|---|---|
api
|
CocApi instance in async mode.
TYPE:
|
state
|
Shared polling state.
TYPE:
|
queue
|
Event queue for detected changes.
TYPE:
|
interval
|
Seconds between probes (default 30).
TYPE:
|
probe_tag
|
Player tag to probe for availability.
TYPE:
|
Source code in cocapi/events/_watchers.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |