Last active
September 23, 2019 17:30
-
-
Save briandfoy/ab67eb63d1d99d98a47e80995c86f72a to your computer and use it in GitHub Desktop.
Is the current episode of This American Life new?
This file contains hidden or 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
#!/Users/brian/bin/perl | |
use v5.26; | |
use Mojo::UserAgent; | |
use Term::ANSIColor; | |
my $ua = Mojo::UserAgent->new; | |
my $url = 'https://www.thisamericanlife.org/archive'; | |
my $tx = $ua->get( $url ); | |
my $episodes = $tx->result->dom | |
->find( 'article[data-episode]' ) | |
->map( attr => 'data-episode' ); | |
my $latest = $episodes->first; | |
my $greatest = $episodes->sort( sub { $b <=> $a } )->first; | |
say <<~"HERE"; | |
Episode is $latest | |
Greatest is $greatest | |
@{[ | |
$latest == $greatest ? | |
colored( ['green'], 'This is a new episode' ) | |
: | |
colored( ['red'], 'This is a re-run' ) | |
]} | |
HERE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment