Skip to content

Instantly share code, notes, and snippets.

@shibayu36
Created February 2, 2013 03:45
Show Gist options
  • Save shibayu36/4696029 to your computer and use it in GitHub Desktop.
Save shibayu36/4696029 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Web::Query;
use Perl6::Say;
use List::MoreUtils qw(any);
my $base_url = "http://shibayu36.hatenablog.com";
my $category_keys = [qw(emacs perl book tech)]; # 表示したいcategoryのリスト
my $category_title = {
emacs => 'Emacs',
perl => 'Perl',
book => '本',
tech => '技術',
misc => 'それ以外',
};
my $result = {};
sub fetch {
my ($url) = @_;
wq($url)
->find("#main-inner li")
->each(sub {
my $entry = $_->find("a.entry-title");
my $href = $entry->attr("href");
my $title = $entry->text;
my ($year, $month) = $href =~ m{^/entry/(\d{4})/(\d{2})};
return unless $year == 2013 && $month == 01; # 2013/01の記事
# categoryの所属を探す
my $category_key = 'misc';
my @entry_categories = $_->find(".categories a")->text;
for my $category (@$category_keys) {
if (any { $_ eq $category } @entry_categories) {
$category_key = $category;
last;
}
}
$result->{$category_key} //= {};
$result->{$category_key}->{$href} = {
title => $title,
};
});
}
fetch($base_url . "/archive");
my $count = 0;
for my $category (keys %$result) {
say sprintf("* %s", $category_title->{$category});
my $entries = $result->{$category};
for my $href (keys %$entries) {
say sprintf(
"- [%s:title=%s:bookmark]",
$base_url . $href,
$entries->{$href}->{title},
);
$count++;
}
}
say "entry count : $count";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment