Listening to the Kafka stream

You can set up your own Hopskotch client and listen to the messages sent over the corresponding Kafka topic.

There is a lightweight function that does all that for you if you want to offload these 20 lines:

tdemocracy.listen.listen_to_nuclear_stream(start_at=ConsumerDefaultPosition.EARLIEST, until_eos=False, settings=None, skip_other_versions=False)[source]

Listen to Nuclear stream

Parameters:
  • start_at (Any) – where to start the stream, either of StartPosition.EARLIEST or StartPosition.LATEST

  • until_eos (bool) – Stop loop when the end of the stream is reached or wait for next message (default)

  • settings (Settings | None) – Settings to use, if not passed reads the corresponding from the environment or a .env file. See tdemocracy.settings.Settings for details.

  • skip_other_versions (bool) – Skip alerts with wrong versions (default)

Return type:

Generator[NuclearTransientReport]

Iterate through the generator to start listening::

for report in listen_to_nuclear_stream():
    # run your classification
    ...