keeptabs.util#
Small pure helpers: app directories, durations, timestamps, URL canonicalisation.
Functions
|
A directory under the root, created if missing. |
|
The same document should have the same URL, however it was linked. |
|
Whether an identifier can be used as a store key (it becomes a file name). |
|
The ISO 8601 form used in every stored record. |
|
A short, filesystem-safe, stable identifier for an item key. |
|
Seconds in a duration such as |
|
The directory that holds every spec and every watch's data. |
|
A kebab-case identifier. |
|
A sortable store key for a moment, in UTC. |
|
A timezone-aware datetime from a datetime, an ISO string, or a duration ago. |
|
The current time, timezone-aware, in UTC. |
- keeptabs.util.app_dir(*parts, rootdir=None)[source]#
A directory under the root, created if missing.
- Return type:
- keeptabs.util.canonical_url(url)[source]#
The same document should have the same URL, however it was linked.
Lower-cases the scheme and host, drops the fragment, a trailing slash, default ports and click-tracking parameters, and sorts what is left.
>>> canonical_url('HTTPS://Example.com:443/a/?utm_source=x&b=2&a=1#top') 'https://example.com/a?a=1&b=2'
- Return type:
- keeptabs.util.is_safe_id(identifier)[source]#
Whether an identifier can be used as a store key (it becomes a file name).
Lowercase only, because some file systems do not tell
Feedfromfeed.>>> [is_safe_id(i) for i in ('llama.cpp', 'gen-ai', '../../etc', 'a/b', '', 'Feed', 'con', 'abc.', 'x' * 101)] [True, True, False, False, False, False, False, False, False]
- Return type:
- keeptabs.util.item_id(key)[source]#
A short, filesystem-safe, stable identifier for an item key.
>>> item_id('https://example.com/a') '2dce0a4c50441bfc'
- Return type:
- keeptabs.util.parse_duration(duration)[source]#
Seconds in a duration such as
'30m','6h','1d'or'2w'.>>> parse_duration('6h') 21600.0 >>> parse_duration(90) 90.0
- Return type:
- keeptabs.util.rootdir(rootdir=None)[source]#
The directory that holds every spec and every watch’s data.
Resolution order: the argument, the
KEEPTABS_ROOTDIRenvironment variable,$XDG_DATA_HOME/keeptabs, then~/.local/share/keeptabs.>>> rootdir('/tmp/somewhere').name 'somewhere'
- Return type:
- keeptabs.util.slug(text)[source]#
A kebab-case identifier.
>>> slug('Music AI (real-time)') 'music-ai-real-time'
- Return type:
- keeptabs.util.timestamp_key(when)[source]#
A sortable store key for a moment, in UTC.
>>> timestamp_key('2026-01-02T03:04:05+01:00') '20260102t020405z'
- Return type:
- keeptabs.util.to_datetime(when, *, now=None)[source]#
A timezone-aware datetime from a datetime, an ISO string, or a duration ago.
>>> to_datetime('2026-01-02T03:04:05+00:00').isoformat() '2026-01-02T03:04:05+00:00' >>> base = to_datetime('2026-01-08') >>> to_datetime('7d', now=base).isoformat() '2026-01-01T00:00:00+00:00'
- Return type: