Created
February 8, 2024 02:06
-
-
Save m0rb/2f960c2d7657e5f3596f4c808bc3b7af to your computer and use it in GitHub Desktop.
bluesky websocket firehose client for perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use 5.12.0; | |
use strict; | |
use warnings; | |
use utf8; | |
use AnyEvent::WebSocket::Client; | |
use CBOR::XS; | |
my $derp = AE::cv; | |
my $cbor = CBOR::XS->new; | |
my $bsky_wss = "wss://bsky.network/xrpc/com.atproto.sync.subscribeRepos"; | |
my $client = AnyEvent::WebSocket::Client->new; | |
$client->connect($bsky_wss)->cb(sub { | |
our $input = eval { shift->recv }; | |
if($@) { | |
warn $@; | |
} | |
$input->on(each_message => sub { | |
my ($con,$message) = (@_); | |
my $body = $message->{'body'}; | |
if ( my $got = $cbor->incr_parse_multiple($body) ) { | |
if ($got->{'blocks'}) { | |
print $got->{'blocks'}; | |
} | |
} | |
}); | |
}); | |
$derp->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment