Twitterにまとめ記事を上げる処理は、以下のとおり。
#!/usr/bin/perl require "mimew.pl" ; use Jcode ; use XML::TreePP ; use XML::FeedPP ; use POSIX qw( strftime ) ; use HTML::Entities ; # Twitterの設定 my $twitter_rss = "http://twitter.com/statuses/user_timeline/<フィードの番号>.rss" ; my $twitter_url = "http://twitter.com/" ; # サマリ記事の最終日付保存も兼ねた一時保存 my $twitter_summary = "/var/run/.twitter.html" ; # 記事をMovableTypeに書き込むためのメールの設定 my $prog_sendmail = "/usr/sbin/qmail-inject" ; my $mail2entry = 'MTに投稿するためのメールアドレス' ; my $mail2entry_from = 'MT投稿のFROMアドレス' ; my $tw_last = 0 ; if ( -r "$twitter_summary" ) { @tw_stat = stat( "$twitter_summary" ) ; $tw_last = $tw_stat[ 9 ] ; } # twitterフィードを読み込む my $twitter = XML::FeedPP->new( $twitter_rss ) ; my $count = 0 ; my $subject = "" ; my $text = " \n" ; my $max_time = 0 ; my $auther = "" ; # 各記事をリストアップ foreach $item ( $twitter->get_item() ) { my $ptime = XML::FeedPP::Util::get_epoch( $item->pubDate() ) ; if ( $ptime > $tw_last ) { $max_time = $ptime if ( $ptime > $max_time ) ; my $pstime = strftime( "%m/%d" , localtime( $ptime ) ) ; my $title = Jcode->new( HTML::Entities::decode( $item->title() ) )->euc ; my $link = $item->link() ; my $url = "" ; $title =~ s//>/g ; $title =~ s/&/&/g ; if ( $title =~ s/^(\w+):\s+// ) { $auther = $1 ; } if ( $title =~ /^(.*)\s+((http|https):\/\/\S+)$/ ) { ($title,$url) = ($1,$2) ; $title = "[メモ]" if ( $title eq "" ) ; $url = " / → <a href=\"$url\">$url</a>" ; } $text .= "<li>$pstime <a href=\"$url\">$title</a&" ."\gt;$url</li>\n" ; $count++ ; } } $text .= "
\n" ; $subject = "$auther のつぶやき" ."(".strftime( "%m/%d" , localtime( $max_time ) ).")" ; # 一応ファイルに保存 open( FH , ">$twitter_summary" ) or die( "Can't open file $twitter_summary\n" ) ; if ( $count > 0 ) { print FH "$subject
\n" ; print FH $text ; } close( FH ) ; # メールで送る if ( $count > 0 ) { open( MAIL , "| $prog_sendmail" ) or die( "Can't open program $prog_sendmail\n" ) ; $subject = mimeencode( Jcode->new( $subject )->jis ) ; $text = Jcode->new( $text )->jis ; print MAIL "From: $mail2entry_from\n" ."To: $mail2entry\n" ."Subject: $subject\n" ."Content-Type: text/html; charset=ISO-2022-JP\n" ."Content-Transfer-Encoding: 7bit\n\n" ."$text" ; close( MAIL ) ; }