command line interface mixi (4)

日記の投稿機能部分を作成した。

sub post_new_diary {
my ($title, $body);
$title = $term->readline("件名: ") while !$title;
$body = $term->readline("本文: ") while !$body;
Encode::from_to($title, 'shiftjis', 'euc-jp');
Encode::from_to($body, 'shiftjis', 'euc-jp');
my @items = $mixi->get_add_diary_preview(
'diary_title' => $title,
'diary_body' => $body) or die "投稿に失敗しました。";
_convert(@items);
my $post_data = $items[0];
warn Dumper(@items);
print $OUT "以下の内容で登録します。よろしいですか?\n";
print $OUT "件名: $post_data->{'diary_title'}\n";
print $OUT "本文: $post_data->{'diary_body'}\n";
print $OUT "post_key: $post_data->{'post_key'}\n";
my $ok = $term->readline("(Y/n)? ");
return unless ($ok =~ /y/i or !$ok);
Encode::from_to($post_data->{'diary_title'}, 'shiftjis', 'euc-jp');
Encode::from_to($post_data->{'diary_body'}, 'shiftjis', 'euc-jp');
my @reses = $mixi->get_add_diary_confirm(
'diary_title' => $post_data->{'diary_title'},
'diary_body' => $post_data->{'diary_body'},
'post_key' => $post_data->{'post_key'}) or die "投稿に失敗しました。";
print $OUT "$response[0]->{'subject''}\n";
}

ついつい、Encode::from_to の戻り値が変換結果ではなく、破壊的代入メソッドというのを忘れてしまう。


日記の投稿ができるようになったので、次は日記のコメント投稿を。と思ったのですが、WWW::Mixiの中に、日記のコメントを投稿するメソッドが見つかりませんでした。考えてみれば、WWW::Mixi自体このようなインタラクティブな使い方は想定されていないから、優先度は低い機能かもしれません。どうしよう?

先にメッセージの送信の方をやろうかな。


あと、以前(d:id:smeghead:20070222:1172151969)もWWW::Mixiの中をちょっと弄りましたが、Mixiが返すHTMLが少し変わっているみたいだったので、今日もちょっと弄った。合わせたdiffです。

*** Mixi.pm.org Thu Feb 22 22:25:43 2007
--- Mixi.pm     Sat Mar  3 19:32:25 2007
***************
*** 790,795 ****
--- 790,796 ----
for (my $i = 0; $i < @images or $i < @texts; $i++) {
my $item = {};
my ($image, $text) = ($images[$i], $texts[$i]);
+                       next if $text =~ /^<br>$/;
$text =~ /^\s*([^<>]*)\((\d+)\)<br\b[^<>]*>/ or return $self->log("[warn] name or count is missing in text.\n\t$text\n");
($item->{'subject'}, $item->{'count'}) = ($1, $2);
$image =~ /(<td\b[^<>]*>)(<a\b[^<>]*>)(<img\b[^<>]*>)/ or return $self->log("[warn] td, a or img tag is missing in image.\n\t$image\n");
***************
*** 1628,1637 ****
my $content   = $res->content;
my @items     = ();
my $succeed   = '作成が完了しました。';
!       if ($content =~ /<table BORDER=0 CELLSPACING=0 CELLPADDING=5>(.*?)<\/form>/s) {
$content = $1;
if (index($content, $succeed) != -1) {
!                       my $link = ($content =~ /<form action="(.*?)">/) ? $self->absolute_url($1, $base) : undef;
my $subj = $self->rewrite($content);
$subj =~ s/[\r\n]+//g;
push(@items, {'subject' => $subj, 'result' => 1, 'link' => $link });
--- 1629,1638 ----
my $content   = $res->content;
my @items     = ();
my $succeed   = '作成が完了しました。';
!       if ($content =~ /<table BORDER="?0"? CELLSPACING="?0"? CELLPADDING="?5"?>(.*?)<\/table>/is) {
$content = $1;
if (index($content, $succeed) != -1) {
!                       my $link = ($content =~ /<a href="([^"]*?)">/i) ? $self->absolute_url($1, $base) : undef;
my $subj = $self->rewrite($content);
$subj =~ s/[\r\n]+//g;
push(@items, {'subject' => $subj, 'result' => 1, 'link' => $link });

あと、charsetの問題とかも真面目に考えないとです。今は、Windows限定だし。

今は、STDOUTに吐いてるだけだけど、モチベーションが保てたら、ncurses対応みたいなことができればいいと思います。

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です


The reCAPTCHA verification period has expired. Please reload the page.

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください