-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump.py
More file actions
executable file
·36 lines (28 loc) · 1016 Bytes
/
Copy pathdump.py
File metadata and controls
executable file
·36 lines (28 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
"""Dump all events from a KurrentDB stream to stdout as JSON."""
import json
import sys
import kurrentdbclient as kdbc
CONNSTR = "kurrentdb://admin:changeit@localhost:2113?tls=false"
def main():
if len(sys.argv) < 2:
print(f"usage: {sys.argv[0]} <stream-name>", file=sys.stderr)
print(f" use '$all' to read the $all stream", file=sys.stderr)
sys.exit(1)
stream = sys.argv[1]
client = kdbc.KurrentDBClient(CONNSTR)
if stream == "$all":
reader = client.read_all(resolve_links=True)
else:
reader = client.read_stream(stream, resolve_links=True)
with reader as events:
for event in events:
print(json.dumps({
"stream": event.stream_name,
"id": str(event.id),
"type": event.type,
"position": event.stream_position,
"data": json.loads(event.data) if event.data else None,
}))
if __name__ == "__main__":
main()