一昨日に続いて、今日も海だよりに行ってきた。
アワビの刺身が目的だったわけだけど、
タコしゃぶとアサリの酒蒸しが旨すぎてしょうがない。
ほっけの焼き物も旨かった。
少しでも貢献できればいいなと思ったのでブログに書いてみる。
サイト: http://www.umidayori.sakura.ne.jp/
住所: 北海道札幌市北区北23条西3丁目 ダイアパレス北23条1F
地下鉄 南北線の北24条駅の4番出口から東に10mくらい行った場所にあります。
8月からマグロ祭(予定)らしいので待た行ってきます!
2010/07/30
2010/07/28
YAML 0.71でutf8 flagが自動で付与される
今日、はまったのでメモ
YAML 0.71からLoadFileで読みこんだデータはutf8 flaggedになっている。
まずは検証の準備
チェック用の簡単なスクリプトを用意
読み込むデータをdata.yamlとして保存
実行結果
YAML 0.71からLoadFileで読みこんだデータはutf8 flaggedになっている。
まずは検証の準備
yoshi@mb yaml% cpanm -l 0.71 http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/YAML-0.71.tar.gz yoshi@mb yaml% cpanm -l 0.70 http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/YAML-0.70.tar.gz
チェック用の簡単なスクリプトを用意
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use YAML; | |
use Devel::Peek; | |
my $data = YAML::LoadFile('data.yaml'); | |
print Dump($data->{hoge}); |
読み込むデータをdata.yamlとして保存
--- hoge: fuga
実行結果
yoshi@mb yaml% perl -I0.70/lib/perl5/ yaml-utf8-check.pl SV = PVMG(0x1008a5280) at 0x100830040 REFCNT = 1 FLAGS = (POK,pPOK) IV = 0 NV = 0 PV = 0x1006af9f0 "fuga"\0 CUR = 4 LEN = 8 yoshi@mb yaml% perl -I0.71/lib/perl5/ yaml-utf8-check.pl SV = PVMG(0x1008a56a0) at 0x100988908 REFCNT = 1 FLAGS = (POK,pPOK,UTF8) IV = 0 NV = 0 PV = 0x1006dec10 "fuga"\0 [UTF8 "fuga"] CUR = 4 LEN = 8
2010/07/12
MyOpera BlogをMT形式でExport
Opera BlogでJavaScirptが使えないのでBloggerに移行した。
しかしOpera Blogにはexport機能がないので、
しかしOpera Blogにはexport機能がないので、
- 過去データをmetaWeblog APIとWeb::ScraperでMT形式に変換
- http://code.google.com/p/google-blog-converters-appengine/のmovabletype2blogger.shでxmlに変換
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
package MT::Feed; | |
use strict; | |
use warnings; | |
sub new { | |
my $class = shift; | |
bless { entries => [], delimiter => "--------\n" }, $class; | |
} | |
sub add_entry { | |
my $self = shift; | |
push @{ $self->{entries} }, shift; | |
} | |
sub as_text { | |
my $self = shift; | |
join( $self->{delimiter}, map $_->as_text, @{ $self->{entries} } ) | |
. $self->{delimiter}; | |
} | |
package MT::Entry; | |
use strict; | |
use warnings; | |
use base 'Class::Accessor::Fast'; | |
my @meta = qw/ | |
author title basename status allow_comments allow_pings convert_breaks | |
date tags | |
/; | |
my @multi = qw/body/; | |
__PACKAGE__->mk_accessors( @meta, @multi ); | |
sub as_text { | |
my $self = shift; | |
my @line; | |
foreach my $method (@meta) { | |
next unless $self->$method; | |
my $key = _to_key($method); | |
push @line, sprintf( "%s: %s", $key, $self->$method ); | |
} | |
push @line, "-----"; | |
foreach my $method (@multi) { | |
next unless $self->$method; | |
my $key = _to_key($method); | |
push @line, sprintf( "%s:", $key ); | |
push @line, $self->$method; | |
push @line, "-----"; | |
} | |
return join( "\n", @line ) . "\n"; | |
} | |
sub _to_key { | |
my $method = shift; | |
uc join( ' ', split /_/, $method ); | |
} | |
package main; | |
use strict; | |
use warnings; | |
use XML::RPC; | |
use Web::Scraper; | |
use HTTP::Date; | |
use DateTime; | |
use Encode qw(find_encoding); | |
my $blogid = 'xxxxxx'; | |
my $username = 'yourname'; | |
my $password = 'yourpasswd'; | |
my $number = shift || 10; | |
my $endpoint = 'http://my.opera.com/yourname/blog/api/'; | |
# fetch blog posts using XML RPC | |
my $x = XML::RPC->new($endpoint); | |
my $data = $x->call( 'metaWeblog.getRecentPosts', | |
$blogid, $username, $password, $number, ); | |
# fetch content in HTML, and tags in TEXT | |
my $scraper = scraper { | |
process '//div[@class="content"]', 'content' => 'HTML'; | |
process '//p[@class="tags"]', 'tags' => 'TEXT'; | |
}; | |
my $utf8 = find_encoding('utf8'); | |
my $feed = MT::Feed->new; | |
foreach my $d (@$data) { | |
warn $d->{link}; | |
my $entry = MT::Entry->new( | |
{ author => 'aloelight', | |
title => $d->{title}, | |
basename => 'a.file', | |
status => 'Publish', | |
allow_comments => 1, | |
allow_pings => 1, | |
convert_breaks => 'richtext', | |
} | |
); | |
my $date = do { | |
my $dt = DateTime->from_epoch( | |
epoch => str2time( $d->{dateCreated} ), | |
time_zone => 'Asia/Tokyo', | |
); | |
$dt->strftime('%m/%d/%Y %I:%M:%S %p'); | |
}; | |
$entry->date($date); | |
my $ret = $scraper->scrape( URI->new( $d->{link} ) ); | |
$ret->{content} =~ s/<pre>/<pre class="prettyprint">/g; | |
$entry->body( $utf8->encode( $ret->{content} ) ); | |
$entry->tags( $utf8->encode( $ret->{tags} ) ) if $ret->{tags}; | |
$feed->add_entry($entry); | |
} | |
print $feed->as_text; |
2010/07/05
Plack::Middleware::Parallel::Scoreboard
ちょうどPlackでServerStatus表示機能が欲しかったところで、Parallel::Scoreboardの話しを聞いのでPlack::Middlewareにしてみた。
http://gist.github.com/464066
Opera blogはJavascript使えないから困る
http://gist.github.com/464066
Opera blogはJavascript使えないから困る
登録:
投稿 (Atom)