Skip to content

Instantly share code, notes, and snippets.

@sharl
Created April 4, 2012 08:03
Show Gist options
  • Save sharl/2299606 to your computer and use it in GitHub Desktop.
Save sharl/2299606 to your computer and use it in GitHub Desktop.
haruchan!
#!/usr/bin/perl
use strict;
use POSIX qw(strftime);
use LWP::UserAgent;
use Data::Dumper;
my $save_dir = $ENV{HOME} . '/Dropbox/haruchan/';
my $TARGET = 'http://cgi2.nhk.or.jp/nw9/haruchan/saijiki/index.cgi?entry=%Y%m%d';
my $HARUCHAN = 'http://cgi2.nhk.or.jp/nw9/data/saijiki/images/%Y%m%d_pg7.jpg';
my $MY_HARU = '%Y%m%d_pg7.jpg';
my $target = strftime($TARGET, localtime);
my $haruchan = strftime($HARUCHAN, localtime);
my $my_haru = strftime($save_dir . $MY_HARU, localtime);
if (! -f $my_haru) {
my $ua = LWP::UserAgent->new;
my $head = $ua->head($haruchan, 'Referer' => $target);
if (! $head->previous) {
$ua->get($haruchan, ':content_file' => $my_haru, 'Referer' => $target);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment