-
-
Save titsuki/6d99620463857a071309ed4764b6b543 to your computer and use it in GitHub Desktop.
Wikipedia Recent Change API
This file contains 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
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