会社の近くにさくら水産があるのでお昼によく利用している(一時期は毎日通っていた)。夜は最近は行ってないなあ。
Plagger でさくら水産のランチメニューをごにょごにょするこちらのスクリプトさくら水産の日替わり定食献立表を取得する - noboruhiの日記 - Plaggerグループがそのままだと動かなかったので下記のように書き直してみました。
assets/plugins/CustomFeed-Script/sakura.pl
#!/usr/bin/perl -w
use strict;
use utf8;
use DateTime;
use DateTime::Format::W3CDTF;
use Encode;
use Web::Scraper;
use URI;
use YAML;
my $uri = URI->new("http://www.teraken.co.jp/menu/lunchmenu/index.html");
my $s = scraper {
process "table tr",
"list[]" => scraper {
process 'div[align="right"]', "date" => 'TEXT';
process 'div[align="left"]', "text" => 'TEXT';
result 'date','text';
};
result 'list';
};
my $scr = $s->scrape($uri);
my $feed = {
title => "さくら水産",
link => $uri->as_string,
};
for my $menu (@{$scr}) {
if ($menu->{text} and $menu->{date}){
push @{$feed->{entries}}, {
title => $menu->{text},
date => munge_datetime($menu->{date}),
};
}
}
binmode STDOUT, ":utf8";
print YAML::Dump $feed;
sub munge_datetime {
my ($date) = @_;
$date =~ m!(\d{1,2})月(\d{1,2})日! or die "No match: $date";
my($month, $day) = ($1, $2);
my $dt = DateTime->new(
year => DateTime->now->year,
month => $month,
day => $day,
hour => '12',
minute => '00',
time_zone => 'Asia/Tokyo',
);
return DateTime::Format::W3CDTF->format_datetime($dt);
}
sakuranch.yaml
global:
plugin_path:
- lib/Plagger/Plugin
assets_path: assets
timezone: Asia/Tokyo
log:
level: error
plugins:
- module: CustomFeed::Script
- module: Subscription::Config
config:
feed:
- script:/PATH/TO/assets/plugins/CustomFeed-Script/sakura.pl
- module: Aggregator::Simple
- module: Publish::iCal
config:
dir: .
filename: sakuranch.ics
iCal から sakuranch.ics を照合するのには問題ないのですが、Google Calendar に追加しようとすると文字化けしてうまくいかない。
ボクの iCal の使い方は、Google Calendar をメインにして BusySync で iCal からも参照・変更出来るようにしているというもの。BusySync は『Google Calendar → iCal』『iCal → Google Calendar』の両方とも出来るので iCal で照合したランチメニューを Google Calendar に公開しました。本当は Google Calendar に直接追加して、他のカレンダー同様 BusySync で『Google Calendar → iCal』としたかったのですが。
perl 初心者なので変な書き方してたらすみません><