Last active
August 18, 2025 22:16
-
-
Save m0rb/e0ad2d68cdc9ee6974f623b0bfcde3eb to your computer and use it in GitHub Desktop.
pango feed from a stream.place chat
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 strict; | |
use warnings; | |
use utf8; | |
use DateTime::Format::RFC3339; | |
use AnyEvent::WebSocket::Client; | |
use JSON::Parse qw(parse_json); | |
$| = 1; | |
my $cv = AE::cv; | |
my $client = AnyEvent::WebSocket::Client->new; | |
my $streamplace_wss = "wss://stream.place/api/websocket/".$ARGV[0]; | |
my $logfile = "/home/morb/obs/chatlog.txt"; | |
our %hurf; | |
$client->connect($streamplace_wss)->cb(sub { | |
our $input = eval { shift->recv }; | |
warn if $@; | |
$input->on(each_message => sub { | |
my ($con,$message) = (@_); | |
my $ret = parse_json($message->{'body'}); | |
if ($ret->{'$type'} =~ 'messageView') { | |
my $rgb = sprintf("\#%x%x%x", $ret->{chatProfile}{color}{red}, | |
$ret->{chatProfile}{color}{green}, | |
$ret->{chatProfile}{color}{blue} | |
); | |
$ret->{record}{text} =~ s/<[^>]*>//g; | |
my $epoch = DateTime::Format::RFC3339->parse_datetime( | |
$ret->{record}{createdAt})->epoch; | |
$hurf{$epoch} = "<span color='${rgb}'>\@$ret->{author}{handle}</span>:". | |
" $ret->{record}{text}\n"; | |
open (my $OUT, ">", $logfile); | |
foreach my $out (sort { $b <=> $a } keys %hurf) { | |
print $OUT $hurf{$out}; | |
} | |
close $OUT; | |
} | |
}) | |
}); | |
$cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment