DateTime Archives

Web Scraping with Zydeco

So I like to keep local copies of my blog posts as Atom entries, but noticed yesterday that I had a few gaps in my collection. The Atom feeds offered by only have the most recent articles though, so I decided to write a quick script to scrape the posts. Luckily, I managed to get a table containing the URLs for each post I needed, so I didn't need to bother with following links to find the pages; I just needed to grab the content from them.

I thought some people might find the code interesting especially for its use of lazy attributes. This is one of those "it only needs to be used once, so making the code maintainable isn't important" kinds of projects, do bear that in mind. I've cleaned up the whitespace and added comments for this blog post, but other than that, it's just a quickly hacked together script.

Happy Pi Day!

Did you know that 22/7 is actually a better approximation of pi than 3.14 is?

use DateTime;
use Math::Trig qw(pi);
use Test::More tests => 1;

my $today = DateTime::->now;
my $dm    = sprintf '%d/%d' => ($today->day, $today->month);

	abs( eval($dm) - pi ),
or diag("this test only passes on 22/7")

About Toby Inkster

user-pic I'm tobyink on CPAN, IRC and PerlMonks.