keeptabs.spec#
The watch specification: what one tracked area is, and how it is watched.
A spec is a plain dict on disk (YAML) so an agent can read and write it without
this package. normalize_spec() is the single place that fills defaults and
rejects what cannot work, so every other module may assume a complete spec.
Functions
|
A yes or no, from a boolean or from the words for one. |
|
Sources that wait on a human action that is still open. |
|
One source with defaults filled in and its fields checked. |
|
A complete, checked copy of a watch specification. |
|
A list of strings from what a hand-written spec may hold. |
|
The field of a source that says what to fetch. |
Exceptions
A watch specification that cannot be used, with the reason and the fix. |
- exception keeptabs.spec.SpecError[source]#
Bases:
ValueErrorA watch specification that cannot be used, with the reason and the fix.
- keeptabs.spec.as_bool(value, *, what)[source]#
A yes or no, from a boolean or from the words for one.
>>> as_bool('false', what='enabled'), as_bool(True, what='enabled') (False, True)
- Return type:
- keeptabs.spec.blocked_source_ids(spec)[source]#
Sources that wait on a human action that is still open.
>>> spec = normalize_spec({'id': 'w', 'sources': [{'kind': 'email', 'sender': 'a@b.c', 'id': 'nl'}], ... 'pending_actions': [{'action': 'Subscribe', 'blocks': ['nl']}]}) >>> blocked_source_ids(spec) {'nl'}
- Return type:
- keeptabs.spec.normalize_source(source)[source]#
One source with defaults filled in and its fields checked.
>>> s = normalize_source({'kind': 'feed', 'url': 'https://example.com/feed.xml'}) >>> s['id'], s['cadence'], s['enabled'], s['keep_all'] ('feed-https-example-com-feed-xml-7a775d', '1d', True, False)
A kind with no fetcher of its own is accepted, and says what to fetch in
target:>>> normalize_source({'kind': 'my_api', 'target': 'robots', 'id': 'robots'})['id'] 'robots'
- Return type:
- keeptabs.spec.normalize_spec(spec, *, watch_id=None)[source]#
A complete, checked copy of a watch specification.
Only
id(ortitle) is required: a spec starts as a vague idea.>>> spec = normalize_spec({'title': 'Gen AI', 'keywords': ['diffusion'], 'entities': ['Sora']}) >>> spec['id'], spec['min_score'], spec['digest']['cadence'], spec['sources'] ('gen-ai', 1.0, '1w', []) >>> spec['entities'] [{'name': 'Sora', 'id': 'sora', 'kind': 'thing', 'aliases': []}]
- Return type:
- keeptabs.spec.str_list(value, *, what='value')[source]#
A list of strings from what a hand-written spec may hold.
A bare string is one term, not a list of characters.
>>> str_list('diffusion'), str_list(['LLM', 2026]), str_list(None) (['diffusion'], ['LLM', '2026'], [])
YAML reads an unquoted
NOas false and3.10as 3.1. What was written cannot be recovered, so such a term is refused, with the fix:>>> str_list(['LLM', False], what='keywords') Traceback (most recent call last): ... keeptabs.spec.SpecError: keywords holds False, which is not text. Put the term in quotes, as in "no" or "3.10".
- Return type: