mirror of
https://github.com/OMGeeky/flucto-heisskleber.git
synced 2026-01-03 01:56:40 +01:00
* Add verbose and pretty flags to hkcli. Adds testing for console sink. * Add argparse help strings to hkcli.
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import json
|
|
import time
|
|
|
|
from heisskleber.core.types import AsyncSink, Serializable, Sink
|
|
|
|
|
|
class ConsoleSink(Sink):
|
|
def __init__(self, pretty: bool = False, verbose: bool = False) -> None:
|
|
self.verbose = verbose
|
|
self.pretty = pretty
|
|
|
|
def send(self, data: dict[str, Serializable], topic: str) -> None:
|
|
verbose_topic = topic + ":\t" if self.verbose else ""
|
|
if self.pretty:
|
|
print(verbose_topic + json.dumps(data, indent=4))
|
|
else:
|
|
print(verbose_topic + str(data))
|
|
|
|
|
|
class AsyncConsoleSink(AsyncSink):
|
|
def __init__(self, pretty: bool = False, verbose: bool = False) -> None:
|
|
self.verbose = verbose
|
|
self.pretty = pretty
|
|
|
|
async def send(self, data: dict[str, Serializable], topic: str) -> None:
|
|
verbose_topic = topic + ":\t" if self.verbose else ""
|
|
if self.pretty:
|
|
print(verbose_topic + json.dumps(data, indent=4))
|
|
else:
|
|
print(verbose_topic + str(data))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sink = ConsoleSink()
|
|
while True:
|
|
sink.send({"test": "test"}, "test")
|
|
time.sleep(1)
|