Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Last active September 23, 2019 17: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 briandfoy/ab67eb63d1d99d98a47e80995c86f72a to your computer and use it in GitHub Desktop.
Save briandfoy/ab67eb63d1d99d98a47e80995c86f72a to your computer and use it in GitHub Desktop.
Is the current episode of This American Life new?
#!/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