Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2020 11:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Ottawa traffic news and alerts
use warnings;
use strict;
use Data::Dump qw | dump |;
use LWP::UserAgent;
use JSON::XS;
my $ua = LWP::UserAgent->new();
my $feed = $ua->get('')->content();
my @alerts;
my @lines = split '\n', $feed;
my @summaries = grep(/^\s*<summary/, @lines);
foreach my $item (@summaries) {
$item =~ s/^\s*<summary type="html">(.*)\&lt;br\&gt;\&lt;br&gt;-- Next Info Block --.*<\/summary>$/${1}/;
$item =~ s/\&lt;br\&gt;/|/g;
my @details = split '\|', $item;
my %alert;
foreach (@details) {
my $id = my $content = $_;
$id =~ s/^([^:]*):.*/${1}/;
$content =~ s/^([^:]*): (.*)/${2}/;
$alert{$id} = $content;
push @alerts, \%alert;
print JSON::XS::encode_json(\@alerts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment