User:HighInBC/Category unblock watcher.pl

This code monitors the EventStream and detect additions to CAT:UNBLOCK, automatically opening the user talk page in your browser immediately when it happens.

use strict;
use IO::Socket::SSL;
use JSON qw(decode_json);
use URI::Escape qw(uri_escape_utf8);

my $browser = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe';

my $cl = IO::Socket::SSL->new('stream.wikimedia.org:443');
syswrite($cl, "GET /v2/stream/recentchange HTTP/1.1\r\n");
syswrite($cl, "Host: stream.wikimedia.org\r\n");
syswrite($cl, "User-Agent: curl/7.55.1\r\n");
syswrite($cl, "Accept: */*\r\n");
syswrite($cl, "\r\n");

while ( my $line = <$cl> ) {
  next if(index($line,'data') == -1 );
  next if(index($line,'en.wikipedia') == -1 );
  next if(index($line,'Category:Requests for unblock') == -1 );
  next if(index($line,'added to category') == -1 );
  substr( $line, 0, 6, '' );
  my $data = decode_json( $line );
  $data->{comment} =~ qr/\[\[:User talk:(.*?)\]\]/ || next;
  my $user = $1;
  my $uri = 'https://en.wikipedia.org/wiki/User_talk:'.uri_escape_utf8($user);
  system( $browser, $uri);
  print "\nOpened URI: $uri\n";
}