Created
April 10, 2020 11:44
-
-
Save JohnMertz/b1c4d51a3c5abc43c0f3c3a13613a593 to your computer and use it in GitHub Desktop.
Ottawa traffic news and alerts
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
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
use Data::Dump qw | dump |; | |
use LWP::UserAgent; | |
use JSON::XS; | |
my $ua = LWP::UserAgent->new(); | |
my $feed = $ua->get('http://ottawa.netalerts.ca/ottawa1/feed.atom')->content(); | |
my @alerts; | |
my @lines = split '\n', $feed; | |
my @summaries = grep(/^\s*<summary/, @lines); | |
foreach my $item (@summaries) { | |
$item =~ s/^\s*<summary type="html">(.*)\<br\>\<br>-- Next Info Block --.*<\/summary>$/${1}/; | |
$item =~ s/\<br\>/|/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