Skip to content

Instantly share code, notes, and snippets.

@titsuki
Last active December 23, 2017 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save titsuki/6d99620463857a071309ed4764b6b543 to your computer and use it in GitHub Desktop.
Save titsuki/6d99620463857a071309ed4764b6b543 to your computer and use it in GitHub Desktop.
Wikipedia Recent Change API
use IO::Socket::Async::SSL;
use JSON::Tiny;
my $conn = await IO::Socket::Async::SSL.connect('stream.wikimedia.org', 443);
$conn.print: "GET /v2/stream/recentchange HTTP/1.0\r\nHost: stream.wikimedia.org\r\n\r\n";
react {
whenever $conn {
if $_ ~~ /^^data\:\s(\{.+\})\r*\n/ {
try {
CATCH {
when X::JSON::Tiny::Invalid { $*ERR.say($_) } # (#1)
}
my $json = from-json(~$0);
say $json if $json<wiki> eq 'jawiki'; # (#2)
}
}
}
}
$conn.close;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment