Skip to content

Commit

Permalink
subscribe.py: truncate block bytes, print records in operations
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed May 21, 2024
1 parent 14cd0ff commit 9df7f44
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import os
import sys

from carbox.car import Block, read_car, write_car
from carbox.message import read_event_pair
import dag_cbor
import dag_json
from lexrpc.client import Client

Expand All @@ -19,5 +22,19 @@
scheme = 'http' if host.split(':')[0] == 'localhost' else 'https'
client = Client(f'{scheme}://{host}')
kwargs = {'cursor': sys.argv[2]} if len(sys.argv) == 3 else {}
for msg in client.com.atproto.sync.subscribeRepos(**kwargs):
print(dag_json.encode(msg).decode(), file=sys.stdout, flush=True)

for header, payload in client.com.atproto.sync.subscribeRepos(**kwargs):
output = json.loads(dag_json.encode(payload).decode())
output['blocks'] = output['blocks']['/']['bytes'][:32] + '…'
print(output.get('seq'), header, output,
file=sys.stdout, flush=True)

roots, blocks = read_car(payload['blocks'])
if blocks:
blocks = {block.cid: block for block in blocks}
for op in payload.get('ops', []):
record = blocks[op['cid']].decoded if op['cid'] else ''
print(' ', op['action'], op['path'], record,
file=sys.stdout, flush=True)

print()

0 comments on commit 9df7f44

Please sign in to comment.