somestuff-oepnvstuff 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,180 @@
1
+ /**/.gtfs_cache
2
+ /*.local
3
+ .claude
4
+
5
+ /*gguf*
6
+
7
+ /docker-config
8
+ /docker_build_local.log
9
+
10
+ /ms?hit
11
+ *mstest*py
12
+ *_test.py
13
+ /umqtt
14
+ .idea/
15
+ /upydev_.config
16
+ *.local.*
17
+ /scripts/logdir/
18
+
19
+
20
+ # Byte-compiled / optimized / DLL files
21
+ __pycache__/
22
+ *.py[cod]
23
+ *$py.class
24
+
25
+ # C extensions
26
+ *.so
27
+
28
+ # Distribution / packaging
29
+ .Python
30
+ build/
31
+ develop-eggs/
32
+ dist/
33
+ downloads/
34
+ eggs/
35
+ .eggs/
36
+ lib/
37
+ lib64/
38
+ parts/
39
+ sdist/
40
+ var/
41
+ wheels/
42
+ share/python-wheels/
43
+ *.egg-info/
44
+ .installed.cfg
45
+ *.egg
46
+ MANIFEST
47
+
48
+ # PyInstaller
49
+ # Usually these files are written by a python script from a template
50
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
51
+ *.manifest
52
+ *.spec
53
+
54
+ # Installer logs
55
+ pip-log.txt
56
+ pip-delete-this-directory.txt
57
+
58
+ # Unit test / coverage reports
59
+ htmlcov/
60
+ .tox/
61
+ .nox/
62
+ .coverage
63
+ .coverage.*
64
+ .cache
65
+ nosetests.xml
66
+ coverage.xml
67
+ *.cover
68
+ *.py,cover
69
+ .hypothesis/
70
+ .pytest_cache/
71
+ cover/
72
+
73
+ # Translations
74
+ *.mo
75
+ *.pot
76
+
77
+ # Django stuff:
78
+ *.log
79
+ local_settings.py
80
+ db.sqlite3
81
+ db.sqlite3-journal
82
+
83
+ # Flask stuff:
84
+ instance/
85
+ .webassets-cache
86
+
87
+ # Scrapy stuff:
88
+ .scrapy
89
+
90
+ # Sphinx documentation
91
+ docs/_build/
92
+
93
+ # PyBuilder
94
+ .pybuilder/
95
+ target/
96
+
97
+ # Jupyter Notebook
98
+ .ipynb_checkpoints
99
+
100
+ # IPython
101
+ profile_default/
102
+ ipython_config.py
103
+
104
+ # pyenv
105
+ # For a library or package, you might want to ignore these files since the code is
106
+ # intended to run in multiple environments; otherwise, check them in:
107
+ # .python-version
108
+
109
+ # pipenv
110
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
111
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
112
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
113
+ # install all needed dependencies.
114
+ #Pipfile.lock
115
+
116
+ # poetry
117
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
118
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
119
+ # commonly ignored for libraries.
120
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
121
+ #poetry.lock
122
+
123
+ # pdm
124
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
125
+ #pdm.lock
126
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
127
+ # in version control.
128
+ # https://pdm.fming.dev/#use-with-ide
129
+ .pdm.toml
130
+
131
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
132
+ __pypackages__/
133
+
134
+ # Celery stuff
135
+ celerybeat-schedule
136
+ celerybeat.pid
137
+
138
+ # SageMath parsed files
139
+ *.sage.py
140
+
141
+ # Environments
142
+ .env
143
+ .venv
144
+ env/
145
+ venv/
146
+ ENV/
147
+ env.bak/
148
+ venv.bak/
149
+
150
+ # Spyder project settings
151
+ .spyderproject
152
+ .spyproject
153
+
154
+ # Rope project settings
155
+ .ropeproject
156
+
157
+ # mkdocs documentation
158
+ /site
159
+
160
+ # mypy
161
+ .mypy_cache/
162
+ .dmypy.json
163
+ dmypy.json
164
+
165
+ # Pyre type checker
166
+ .pyre/
167
+
168
+ # pytype static type analyzer
169
+ .pytype/
170
+
171
+ # Cython debug symbols
172
+ cython_debug/
173
+
174
+ # PyCharm
175
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
176
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
177
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
178
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
179
+ #.idea/
180
+
@@ -0,0 +1,163 @@
1
+ GNU Lesser General Public License
2
+ =================================
3
+
4
+ _Version 3, 29 June 2007_
5
+ _Copyright © 2007 Free Software Foundation, Inc. &lt;<http://fsf.org/>&gt;_
6
+
7
+ Everyone is permitted to copy and distribute verbatim copies
8
+ of this license document, but changing it is not allowed.
9
+
10
+
11
+ This version of the GNU Lesser General Public License incorporates
12
+ the terms and conditions of version 3 of the GNU General Public
13
+ License, supplemented by the additional permissions listed below.
14
+
15
+ ### 0. Additional Definitions
16
+
17
+ As used herein, “this License” refers to version 3 of the GNU Lesser
18
+ General Public License, and the “GNU GPL” refers to version 3 of the GNU
19
+ General Public License.
20
+
21
+ “The Library” refers to a covered work governed by this License,
22
+ other than an Application or a Combined Work as defined below.
23
+
24
+ An “Application” is any work that makes use of an interface provided
25
+ by the Library, but which is not otherwise based on the Library.
26
+ Defining a subclass of a class defined by the Library is deemed a mode
27
+ of using an interface provided by the Library.
28
+
29
+ A “Combined Work” is a work produced by combining or linking an
30
+ Application with the Library. The particular version of the Library
31
+ with which the Combined Work was made is also called the “Linked
32
+ Version”.
33
+
34
+ The “Minimal Corresponding Source” for a Combined Work means the
35
+ Corresponding Source for the Combined Work, excluding any source code
36
+ for portions of the Combined Work that, considered in isolation, are
37
+ based on the Application, and not on the Linked Version.
38
+
39
+ The “Corresponding Application Code” for a Combined Work means the
40
+ object code and/or source code for the Application, including any data
41
+ and utility programs needed for reproducing the Combined Work from the
42
+ Application, but excluding the System Libraries of the Combined Work.
43
+
44
+ ### 1. Exception to Section 3 of the GNU GPL
45
+
46
+ You may convey a covered work under sections 3 and 4 of this License
47
+ without being bound by section 3 of the GNU GPL.
48
+
49
+ ### 2. Conveying Modified Versions
50
+
51
+ If you modify a copy of the Library, and, in your modifications, a
52
+ facility refers to a function or data to be supplied by an Application
53
+ that uses the facility (other than as an argument passed when the
54
+ facility is invoked), then you may convey a copy of the modified
55
+ version:
56
+
57
+ * **a)** under this License, provided that you make a good faith effort to
58
+ ensure that, in the event an Application does not supply the
59
+ function or data, the facility still operates, and performs
60
+ whatever part of its purpose remains meaningful, or
61
+
62
+ * **b)** under the GNU GPL, with none of the additional permissions of
63
+ this License applicable to that copy.
64
+
65
+ ### 3. Object Code Incorporating Material from Library Header Files
66
+
67
+ The object code form of an Application may incorporate material from
68
+ a header file that is part of the Library. You may convey such object
69
+ code under terms of your choice, provided that, if the incorporated
70
+ material is not limited to numerical parameters, data structure
71
+ layouts and accessors, or small macros, inline functions and templates
72
+ (ten or fewer lines in length), you do both of the following:
73
+
74
+ * **a)** Give prominent notice with each copy of the object code that the
75
+ Library is used in it and that the Library and its use are
76
+ covered by this License.
77
+ * **b)** Accompany the object code with a copy of the GNU GPL and this license
78
+ document.
79
+
80
+ ### 4. Combined Works
81
+
82
+ You may convey a Combined Work under terms of your choice that,
83
+ taken together, effectively do not restrict modification of the
84
+ portions of the Library contained in the Combined Work and reverse
85
+ engineering for debugging such modifications, if you also do each of
86
+ the following:
87
+
88
+ * **a)** Give prominent notice with each copy of the Combined Work that
89
+ the Library is used in it and that the Library and its use are
90
+ covered by this License.
91
+
92
+ * **b)** Accompany the Combined Work with a copy of the GNU GPL and this license
93
+ document.
94
+
95
+ * **c)** For a Combined Work that displays copyright notices during
96
+ execution, include the copyright notice for the Library among
97
+ these notices, as well as a reference directing the user to the
98
+ copies of the GNU GPL and this license document.
99
+
100
+ * **d)** Do one of the following:
101
+ - **0)** Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+ - **1)** Use a suitable shared library mechanism for linking with the
109
+ Library. A suitable mechanism is one that **(a)** uses at run time
110
+ a copy of the Library already present on the user's computer
111
+ system, and **(b)** will operate properly with a modified version
112
+ of the Library that is interface-compatible with the Linked
113
+ Version.
114
+
115
+ * **e)** Provide Installation Information, but only if you would otherwise
116
+ be required to provide such information under section 6 of the
117
+ GNU GPL, and only to the extent that such information is
118
+ necessary to install and execute a modified version of the
119
+ Combined Work produced by recombining or relinking the
120
+ Application with a modified version of the Linked Version. (If
121
+ you use option **4d0**, the Installation Information must accompany
122
+ the Minimal Corresponding Source and Corresponding Application
123
+ Code. If you use option **4d1**, you must provide the Installation
124
+ Information in the manner specified by section 6 of the GNU GPL
125
+ for conveying Corresponding Source.)
126
+
127
+ ### 5. Combined Libraries
128
+
129
+ You may place library facilities that are a work based on the
130
+ Library side by side in a single library together with other library
131
+ facilities that are not Applications and are not covered by this
132
+ License, and convey such a combined library under terms of your
133
+ choice, if you do both of the following:
134
+
135
+ * **a)** Accompany the combined library with a copy of the same work based
136
+ on the Library, uncombined with any other library facilities,
137
+ conveyed under the terms of this License.
138
+ * **b)** Give prominent notice with the combined library that part of it
139
+ is a work based on the Library, and explaining where to find the
140
+ accompanying uncombined form of the same work.
141
+
142
+ ### 6. Revised Versions of the GNU Lesser General Public License
143
+
144
+ The Free Software Foundation may publish revised and/or new versions
145
+ of the GNU Lesser General Public License from time to time. Such new
146
+ versions will be similar in spirit to the present version, but may
147
+ differ in detail to address new problems or concerns.
148
+
149
+ Each version is given a distinguishing version number. If the
150
+ Library as you received it specifies that a certain numbered version
151
+ of the GNU Lesser General Public License “or any later version”
152
+ applies to it, you have the option of following the terms and
153
+ conditions either of that published version or of any later version
154
+ published by the Free Software Foundation. If the Library as you
155
+ received it does not specify a version number of the GNU Lesser
156
+ General Public License, you may choose any version of the GNU Lesser
157
+ General Public License ever published by the Free Software Foundation.
158
+
159
+ If the Library as you received it specifies that a proxy can decide
160
+ whether future versions of the GNU Lesser General Public License shall
161
+ apply, that proxy's public statement of acceptance of any version is
162
+ permanent authorization for you to choose that version for the
163
+ Library.
@@ -0,0 +1,301 @@
1
+ Metadata-Version: 2.5
2
+ Name: somestuff-oepnvstuff
3
+ Version: 0.2.3
4
+ Summary: GTFS-Realtime coverage checker: does an open GTFS-RT feed carry real-time data for your lines at your stop? One-shot or MQTT-publishing watcher
5
+ Project-URL: Homepage, https://github.com/vroomfondel/somestuff
6
+ Project-URL: Repository, https://github.com/vroomfondel/somestuff
7
+ Project-URL: Issues, https://github.com/vroomfondel/somestuff/issues
8
+ Author-email: Henning Thieß <ht@xomox.cc>
9
+ License-File: LICENSE.md
10
+ Keywords: gtfs,gtfs-realtime,monitoring,mqtt,oepnv,public-transport,transit
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Scientific/Engineering :: GIS
19
+ Classifier: Topic :: System :: Monitoring
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.13
22
+ Requires-Dist: gtfs-realtime-bindings>=2.2
23
+ Requires-Dist: loguru>=0.7.3
24
+ Requires-Dist: mqttstuff>=0.0.7
25
+ Requires-Dist: python-dotenv>=1.2
26
+ Requires-Dist: requests>=2.34
27
+ Requires-Dist: tabulate>=0.10
28
+ Requires-Dist: typer>=0.27
29
+ Description-Content-Type: text/markdown
30
+
31
+ # oepnvstuff
32
+
33
+ Validate whether an open GTFS-Realtime feed actually carries real-time data
34
+ (delays / actual times) for specific transit lines at a specific station, either
35
+ as a one-shot check or as a long-running watcher that publishes its findings to
36
+ MQTT.
37
+
38
+ Open-data GTFS-RT aggregators (such as gtfs.de) merge whatever the transit
39
+ agencies deliver. For many rural and suburban lines that is schedule only: the
40
+ feed exists, but your lines never get actual times. This tool answers "is there
41
+ real realtime for my lines at my stop?" before you build anything on top of it.
42
+ The defaults (station `Blankenese`, lines `1/12/22/189`) are just defaults;
43
+ every parameter is overridable via CLI option or `OEPNV_*` environment variable.
44
+
45
+ ## Modules
46
+
47
+ - **`check_realtime.py`** — Typer CLI: one-shot check or `--watch` poll loop,
48
+ console report, optional MQTT publishing.
49
+ - **`monitor.py`** — `RealtimeMonitor`: poll loop with staleness detection that
50
+ dispatches typed results to pluggable `on_*` handlers (cycle, alert, stale,
51
+ error). Console output and the MQTT bridge are just handlers.
52
+ - **`gtfs_static.py`** — static feed: cached download with conditional GET plus
53
+ schedule indexing (`StaticFeedIndex`): matched stops, routes of the target
54
+ lines, and the trips that belong to those lines and serve a matched stop.
55
+ - **`gtfs_realtime.py`** — realtime feed: `RealtimeFetcher` (ETag /
56
+ If-Modified-Since) and protobuf parsing into a `RealtimeSnapshot`
57
+ (TripUpdates + ServiceAlerts).
58
+ - **`mqtt_bridge.py`** — `GtfsMqttBridge`: publishes cycle and line status,
59
+ departures, new alerts and stale transitions via `mqttstuff`.
60
+
61
+ Only `mqtt_bridge.py` imports `mqttstuff`; the core runs without a broker.
62
+ Logging (loguru, with an intercept for stdlib `logging`, e.g. `requests` and
63
+ `paho-mqtt`) and the startup banner are shared via `somestuff.oepnvstuff`.
64
+
65
+ ### How it works
66
+
67
+ 1. The static GTFS feed (planned schedule, one big zip) is downloaded once and
68
+ indexed: stops whose name contains the station query, the routes of the target
69
+ lines, and the trips of those lines that serve one of the matched stops. Next
70
+ to the cached zip a `<name>.meta.json` sidecar stores the server's
71
+ `ETag`/`Last-Modified`; every later run sends a conditional GET, so an
72
+ unchanged feed costs a `304` round-trip instead of a re-download.
73
+ 2. The realtime feed (`.pb`, TripUpdates + ServiceAlerts) is fetched, or in
74
+ `--watch` mode polled (GTFS-RT is not push/WebSocket). The fetcher keeps the
75
+ HTTP validators between polls, so unchanged cycles are `304`s.
76
+ 3. TripUpdates are matched against the target trips (`trip_id`) and target lines
77
+ (`route_id`); delay values are aggregated per line.
78
+ 4. Staleness is detected two ways, and either marks the cycle stale: the feed's
79
+ own `FeedHeader.timestamp` is older than `--max-age` seconds, or
80
+ `--stale-cycles` consecutive cycles passed without a timestamp change.
81
+
82
+ ## Installation
83
+
84
+ ```bash
85
+ pip install somestuff-oepnvstuff
86
+ ```
87
+
88
+ `somestuff` is a PEP 420 namespace; the package is imported as
89
+ `somestuff.oepnvstuff` and shares the namespace with the other `somestuff-*`
90
+ distributions.
91
+
92
+ ## Usage
93
+
94
+ Console script and module invocation are equivalent:
95
+
96
+ ```bash
97
+ oepnv-check-realtime
98
+ python3 -m somestuff.oepnvstuff.check_realtime
99
+ ```
100
+
101
+ One-shot check (human-readable report, the exit code summarises the result):
102
+
103
+ ```bash
104
+ oepnv-check-realtime
105
+ oepnv-check-realtime --station "Blankenese" --lines "286,488"
106
+ ```
107
+
108
+ Both feed options also accept local file paths (handy for tests):
109
+ `--static feed.zip --realtime snapshot.pb`.
110
+
111
+ Exit codes: `0` realtime found for at least one line (or watch ended cleanly),
112
+ `2` schedule found but no realtime (or stale abort), `3` no matching stops or
113
+ trips in the static feed, `1` technical error.
114
+
115
+ ### Stations, lines and `--near`
116
+
117
+ ```bash
118
+ # which stops would match? Reads only stops.txt plus one stop_times pass and
119
+ # shows coordinates, serving lines (incl. agency) and directions per stop
120
+ oepnv-check-realtime --show-stops
121
+
122
+ # several stations at once, ';'-separated (stop names contain commas and spaces)
123
+ oepnv-check-realtime --station "Blankenese;Ellerbek" --lines "1,189,195"
124
+
125
+ # same-named stations in different towns? GTFS has no postal codes, so filter
126
+ # geographically by 'lat,lon,radius_km'; applies to the check itself as well.
127
+ # Several areas are ';'-separated and OR-combined.
128
+ oepnv-check-realtime --show-stops --station Blankenese --near 53.5633,9.8144,2
129
+ oepnv-check-realtime --near "53.5633,9.8144,2;53.647,9.892,3"
130
+ ```
131
+
132
+ ### Watch mode
133
+
134
+ ```bash
135
+ # poll loop, one compact status line per cycle
136
+ oepnv-check-realtime --watch --interval 180
137
+
138
+ # exit with code 2 once the feed goes stale (lets a supervisor restart it)
139
+ oepnv-check-realtime --watch --stop-on-stale
140
+ ```
141
+
142
+ ### Departures
143
+
144
+ ```bash
145
+ # next N departures per line+direction, with realtime delay
146
+ # ("1 Richtung S Rissen: in 2 min (+80s)")
147
+ oepnv-check-realtime --watch --departures --departures-count 2
148
+ ```
149
+
150
+ `--departures-horizon` sets the look-ahead window in hours (default 48).
151
+
152
+ ### MQTT
153
+
154
+ ```bash
155
+ oepnv-check-realtime --watch --mqtt --mqtt-host broker.example.org
156
+ mosquitto_sub -h broker.example.org -v -t 'oepnv/#'
157
+ ```
158
+
159
+ With `base_topic` at its default `oepnv`:
160
+
161
+ | Topic | Payload |
162
+ |----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
163
+ | `oepnv/status` | per-cycle summary: feed ts/age, stale flag, per-line hit counts |
164
+ | `oepnv/lines/<line>/status` | one line: `updates`, `delay_min/max/avg_s`, `static_trips` |
165
+ | `oepnv/departures` | with `--departures`: all upcoming departures in one document (`in_minutes`, `delay_s`, `realtime`, stop, times); published every cycle, empty list when the board is empty |
166
+ | `oepnv/departures/<line>/<stop>/<direction>` | one group's departures; ASCII-simplified segments (`departures/1/S_Blankenese/U_Kellinghusenstrasse`) |
167
+ | `oepnv/alerts` | each new (deduplicated) service alert: `{entity, text}` |
168
+ | `oepnv/stale` | fired once on the transition into staleness |
169
+
170
+ Everything is published with `retain=False`: the broker keeps no last value and
171
+ subscribers see the live stream only. A late subscriber waits at most one poll
172
+ interval for the next status/departures cycle.
173
+
174
+ ## Configuration
175
+
176
+ Precedence: CLI option > real environment variable > `./oepnv.local.env` (current
177
+ working directory) > `oepnv.local.env` next to the installed `check_realtime`
178
+ module. Both env files are auto-loaded via `python-dotenv` and never override
179
+ variables that are already set. An example env file ships in the repository, not
180
+ in the wheel:
181
+ https://github.com/vroomfondel/somestuff/tree/main/somestuff/oepnvstuff/
182
+
183
+ | Env var | CLI | Default |
184
+ |----------------------------------|--------------------------------|-----------------------------------------------------------------------------------------------|
185
+ | `OEPNV_STATIC_URL` | `--static` | `https://download.gtfs.de/germany/nv_free/latest.zip` (URL or `.zip` path) |
186
+ | `OEPNV_REALTIME_URL` | `--realtime` | `https://realtime.gtfs.de/realtime-free.pb` (URL or `.pb` path) |
187
+ | `OEPNV_LINES` | `--lines`, `-l` | `1,12,22,189` (comma/space separated) |
188
+ | `OEPNV_STATION` | `--station`, `-s` | `Blankenese` (case-insensitive substring match; several stations `;`-separated) |
189
+ | `OEPNV_NEAR` | `--near` | off; `lat,lon,radius_km` geo filter for the matched stops, areas `;`-separated (OR) |
190
+ | `OEPNV_ENABLE_DEPARTURES` | `--departures/--no-departures` | off; report upcoming departures per line+direction |
191
+ | `OEPNV_DEPARTURES_COUNT` | `--departures-count` | `3`; next N departures per line+direction |
192
+ | `OEPNV_DEPARTURES_HORIZON_HOURS` | `--departures-horizon` | `48` h look-ahead |
193
+ | `OEPNV_CACHE_DIR` | `--cache-dir` | `.gtfs_cache` |
194
+ | `OEPNV_FORCE_REFRESH` | `--force-refresh` | off; re-download the static zip even on `304` |
195
+ | `OEPNV_WATCH` | `--watch`, `-w` | off |
196
+ | `OEPNV_INTERVAL` | `--interval` | `180` s, see Bandwidth below |
197
+ | `OEPNV_MAX_AGE` | `--max-age` | `120` s (`0` = off) |
198
+ | `OEPNV_STALE_CYCLES` | `--stale-cycles` | `6` |
199
+ | `OEPNV_STOP_ON_STALE` | `--stop-on-stale` | off |
200
+ | `OEPNV_RECENT_WINDOW` | `--recent-window` | `900` s; a line still counts as `realtime_recent` this long after its last update (`0` = off) |
201
+ | `OEPNV_MQTT_ENABLE` | `--mqtt/--no-mqtt` | off |
202
+ | `OEPNV_MQTT_HOST` | `--mqtt-host` | `mosquitto.mosquitto.svc.cluster.local` |
203
+ | `OEPNV_MQTT_PORT` | `--mqtt-port` | `1883` |
204
+ | `OEPNV_MQTT_USER` | `--mqtt-user` | anonymous |
205
+ | `OEPNV_MQTT_PASSWORD` | `--mqtt-password` | empty |
206
+ | `OEPNV_MQTT_BASE_TOPIC` | `--mqtt-base-topic` | `oepnv` |
207
+ | `OEPNV_MQTT_TLS` | `--mqtt-tls` | off; the port is not switched automatically, TLS brokers usually listen on `8883` |
208
+ | `OEPNV_MQTT_TLS_CA` | `--mqtt-tls-ca` | system CA store; CA certificate path |
209
+ | `OEPNV_MQTT_TLS_CERT` | `--mqtt-tls-cert` | off; client certificate for mutual TLS (with `OEPNV_MQTT_TLS_KEY`) |
210
+ | `OEPNV_MQTT_TLS_KEY` | `--mqtt-tls-key` | off; client key for mutual TLS |
211
+ | `OEPNV_MQTT_TLS_INSECURE` | `--mqtt-tls-insecure` | off; skip hostname verification (self-signed certs), chain verification still applies |
212
+ | `OEPNV_VERBOSE` | `--verbose`, `-v` | off; DEBUG logging |
213
+
214
+ `--show-stops` has no environment variable.
215
+
216
+ ### Bandwidth
217
+
218
+ `OEPNV_INTERVAL` is the only lever on data volume, for a reason that is not
219
+ obvious:
220
+
221
+ - `RealtimeFetcher` sends conditional requests (`If-None-Match` /
222
+ `If-Modified-Since`) and gtfs.de answers them correctly with `304`.
223
+ - gtfs.de rebuilds `realtime-free.pb` once per minute (`FeedHeader.timestamp`
224
+ always lands on `:50`). With an interval of 60 s or less every poll is
225
+ therefore a genuinely new body; the `304` is structurally unreachable, not
226
+ broken.
227
+ - The feed is uncompressed (no `Content-Encoding`) and there is no smaller
228
+ regional variant: `realtime-{nv,fv,rv}.pb` return 404, only the nationwide
229
+ feed exists.
230
+
231
+ Volume therefore depends only on how many feed versions are fetched, not on how
232
+ often you poll. Polling faster than the rebuild costs nothing (the extra polls
233
+ are `304`s); polling slower is the only saving. Measured over 360 cycles: about
234
+ 44 MB per version (min 29, max 53).
235
+
236
+ | Interval | Versions/day | Volume/day |
237
+ |-----------------|--------------|------------|
238
+ | 20-60 s | 1440 | ~61 GB |
239
+ | 180 s (default) | 480 | ~20 GB |
240
+ | 300 s | 288 | ~12 GB |
241
+ | 600 s | 144 | ~6 GB |
242
+
243
+ `OEPNV_MAX_AGE` does not have to grow with the interval: `age` is
244
+ `now - feed_ts` at fetch time and stays below 60 s because of the per-minute
245
+ rebuild, regardless of the interval.
246
+
247
+ ### Kubernetes
248
+
249
+ Configure everything via env in the Deployment. Point `OEPNV_CACHE_DIR` at a
250
+ persistent volume so pod restarts reuse the large static zip via `304`, and
251
+ combine `OEPNV_WATCH=1` with `OEPNV_STOP_ON_STALE=1` so a dead feed exits with
252
+ code 2 and the kubelet restarts the pod. A ready-made Deployment (watch + MQTT +
253
+ cache volume) and a Secret example for the broker credentials are in the
254
+ repository, not in the wheel:
255
+ https://github.com/vroomfondel/somestuff/tree/main/somestuff/oepnvstuff/
256
+
257
+ ## Library
258
+
259
+ The monitor knows nothing about consoles or brokers: it dispatches typed
260
+ results to registered handlers. Add your own the same way the console report and
261
+ the MQTT bridge do:
262
+
263
+ ```python
264
+ from somestuff.oepnvstuff.gtfs_realtime import RealtimeFetcher
265
+ from somestuff.oepnvstuff.gtfs_static import build_index, obtain
266
+ from somestuff.oepnvstuff.monitor import CycleResult, RealtimeMonitor
267
+
268
+ index = build_index(obtain("https://download.gtfs.de/germany/nv_free/latest.zip", ".gtfs_cache"),
269
+ ["1", "189"], "Blankenese")
270
+ monitor = RealtimeMonitor(RealtimeFetcher("https://realtime.gtfs.de/realtime-free.pb"), index,
271
+ interval=180.0, stop_on_stale=True)
272
+
273
+ def my_handler(cycle: CycleResult) -> None:
274
+ for line, status in cycle.per_line.items():
275
+ print(line, status.updates, status.avg_delay)
276
+
277
+ monitor.add_cycle_handler(my_handler) # every completed cycle
278
+ monitor.add_alert_handler(print) # each new service alert (deduplicated)
279
+ monitor.add_stale_handler(print) # edge-triggered on going stale
280
+ monitor.add_error_handler(print) # fetch errors (loop keeps running)
281
+
282
+ raise SystemExit(monitor.watch()) # or: monitor.check_once()
283
+ ```
284
+
285
+ Handler exceptions are logged and swallowed, so one misbehaving sink cannot kill
286
+ the poll loop.
287
+
288
+ ## Data sources
289
+
290
+ The defaults are the free, registration-less feeds from gtfs.de (CC BY-SA 4.0,
291
+ https://gtfs.de/de/open-data/): static `germany/nv_free/latest.zip` (German
292
+ regional transit) and `realtime-free.pb` (TripUpdates + ServiceAlerts). Any other
293
+ GTFS / GTFS-RT pair works via `--static` / `--realtime`, for example an agency's
294
+ own feed if the open aggregate turns out to lack your lines (for HVV territory:
295
+ Geofox-GTI).
296
+
297
+ ## Notes
298
+
299
+ - Requires: `loguru`, `typer`, `gtfs-realtime-bindings`, `python-dotenv`,
300
+ `requests`, `tabulate`, `mqttstuff`.
301
+ - Licensed under the LGPL, see `LICENSE.md` in the repository root.