Yahoo!Pipesを試してみる
なぜ今頃Pipes?
2、3日前にいくつかのFeedをまとめるPipesってなかったけ?って話をTwitterでしていたら、caramel*vanillaのlomoさんが見てたようで、「じゃあ作ったる→出来た→」http://caramel-tea.com/2007/05/merge_pipes/というのがあっという間だったので、自分も覚えたいなと
で、まずは簡単なものから作ってみた。
今回試してみること
データ
これが
<?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0" xmlns:ldWeather="http://weather.livedoor.com/ns/rss/2.0"> <channel> 〜 略 〜 <item> <title>[ PR ] ブログで福島県のお天気を簡単ゲット!</title> <link>http://weather.livedoor.com/weather_hacks/plugin.html?pref=7</link> <category>PR</category> <description>livedoor 天気情報「Weather Hacks」では一般のブロガーの皆さん向けにブログでお天気を表示できる、お天気プラグインを公開しました。使い方はとってもカンタン!手順に沿って作成したHTMLソースを自分のブログに貼り付けるだけです!</description> <image> <title>お天気プラグイン - livedoor 天気情報</title> <link>http://weather.livedoor.com/weather_hacks/plugin.html?pref=7</link> <url>http://image.weather.livedoor.com/img/weather_hacks/news_title.gif</url> <width>151</width> <height>50</height> </image> <pubDate>Tue, 22 May 2007 08:00:00 +0900</pubDate> </item> <item> <title>[ 22日(火)の天気 ] 小名浜 - 晴れ - 最高気温19℃ - 5月22日(火)</title> <link>http://weather.livedoor.com/area/7/32.html?r=rss20070522</link> <category>天気予報</category> <day>Tuesday</day> <image> <title>晴れ</title> <link>http://weather.livedoor.com/area/7/32.html?r=rss20070522</link> <url>http://image.weather.livedoor.com/img/icon/1.gif</url> <width>50</width> <height>31</height> </image> <description>22日(火)の天気は晴れ、最高気温は19℃ 最低気温は12℃でしょう。</description> <pubDate>Tue, 22 May 2007 11:00:00 +0900</pubDate> </item> <item> <title>[ 23日(水)の天気 ] 小名浜 - 晴れ - 最高気温23℃ - 5月23日(水)</title> <link>http://weather.livedoor.com/area/7/32.html?r=rss20070523</link> <category>天気予報</category> <day>Wednesday</day> <image> <title>晴れ</title> <link>http://weather.livedoor.com/area/7/32.html?r=rss20070523</link> <url>http://image.weather.livedoor.com/img/icon/1.gif</url> <width>50</width> <height>31</height> </image> <description>23日(水)の天気は晴れ、最高気温は23℃ 最低気温は13℃でしょう。</description> <pubDate>Tue, 22 May 2007 11:00:00 +0900</pubDate> </item> <item> <title>[ 24日(木)の天気 ] 小名浜 - 晴時々曇 - 最高気温28℃ - 5月24日(木)</title> <link>http://weather.livedoor.com/area/7/32.html?r=rss20070524</link> <category>天気予報</category> <day>Thursday</day> <image> <title>晴時々曇</title> <link>http://weather.livedoor.com/area/7/32.html?r=rss20070524</link> <url>http://image.weather.livedoor.com/img/icon/2.gif</url> <width>50</width> <height>31</height> </image> <description>24日(木)の天気は晴時々曇、最高気温は28℃ 最低気温は13℃でしょう。</description> <pubDate>Tue, 22 May 2007 11:00:00 +0900</pubDate> </item> <item> 〜 略 〜 <pubDate>Tue, 22 May 2007 11:00:00 +0900</pubDate> <guid isPermaLink="true">http://weather.livedoor.com/area/7/32.html?r=rss</guid> </channel> </rss>
こうなる
<?xml version="1.0" ?> <rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/"> <channel> <title>小名浜の天気</title> <description>livedoor 天気情報の小名浜のRSSから今日、明日、明後日のデータだけを抜き出す</description> <link>http://pipes.yahoo.com/pipes/pipe.info?_id=Nr6fM2IH3BGpj2RXouNLYQ</link> <pubDate>Mon, 21 May 2007 22:21:32 -0700</pubDate> <generator>http://pipes.yahoo.com/pipes/</generator> <item> <title>[ 22日(火)の天気 ] 小名浜 - 晴れ - 最高気温19℃ - 5月22日(火)</title> <link>http://weather.livedoor.com/area/7/32.html?r=rss20070522</link> <description>22日(火)晴れ、最高19℃ 最低12℃</description> <guid isPermaLink="false" /> <pubDate>Mon, 21 May 2007 19:00:00 -0700</pubDate> </item> <item> <title>[ 23日(水)の天気 ] 小名浜 - 晴れ - 最高気温23℃ - 5月23日(水)</title> <link>http://weather.livedoor.com/area/7/32.html?r=rss20070523</link> <description>23日(水)晴れ、最高23℃ 最低13℃</description> <guid isPermaLink="false" /> <pubDate>Mon, 21 May 2007 19:00:00 -0700</pubDate> </item> <item> <title>[ 24日(木)の天気 ] 小名浜 - 晴時々曇 - 最高気温28℃ - 5月24日(木)</title> <link>http://weather.livedoor.com/area/7/32.html?r=rss20070524</link> <description>24日(木)晴時々曇、最高28℃ 最低13℃</description> <guid isPermaLink="false" /> <pubDate>Mon, 21 May 2007 19:00:00 -0700</pubDate> </item> </channel> </rss> <!-- m11.pipes.re3.yahoo.com uncompressed Mon May 21 22:21:31 PDT 2007 -->
Pipesの設定
- Sourece>Feth FeedのURL欄に「http://weather.livedoor.com/forecast/rss/7/32.xml」
- Operators>TruncateのTruncate feed after欄に「4」先頭から4件だけ抽出
- Operators>Filterで合致したデータを捨てたいので「Block」、条件に「item.category」が合致したらなので「is」、文字列は「PR」
→2.3.は、おそらくFilterの方が高価な命令だと思ったので先にデータ件数を絞ったのだが、順番が変わっても特に速度は変わらないみたい - Operators>Regexで
の文言を「22日(火)の天気は晴れ、最高気温は19℃ 最低気温は12℃でしょう。」から「22日(火)晴れ、最高19℃ 最低12℃」に加工する
今回ハマったのがここで、サンプルを見ても最初はわからなかったが、ようは加工したい単位に正規表現を()で括って、文字列を加えたり、削除するということに気がつきサクサク?と
In:対象の要素に「item.description」、replace:検索又は置換対象の正規表現に「(.*)(の天気は)(.*)(気温は)(.*)(気温は)(.*)(でしょう。.*$)」、with:どう置き換えるかに「$1$3$5$7」で持ってきたいグループ(何個目の括弧で括っている塊か)を指定
あとはPublishして名前やコメントを記入して、Run this Pipesして出来たRSSをTumblrのFeedsに設定する(as text without titlesにしないとタイトルも表示される)
今後やってみたいこと
出来るかどうかはわからないが、descriptionでtitleを加工したり、description内の日付を今日、明日、明後日に置き換えたり、三日分のdescriptionを一まとめにしたり出来るかを調査してみたい
感想
意外に簡単なのはすぐ作れそう、ただ、「weather_tohoku」の配信の仕組みをPerlで記述しているのを置き換えたりするのはしないと思う
朝に、ダイレクトメッセージでWishLinesの新着アイテムと本日発売を送っているが、ちょっと弄れば(タイトルにd 俺と入れればダイレクトメッセージになるかな?)できるかも知れないなとは思った
雑感
これはAmazon側の問題だからどうしようもないんだけど、Wishlinesの検索ワードに関係ないのが引っかかって送られてくるのが何だか微妙
たとえば「伊藤誠((舞弥とか兎を書いている漫画家」って検索ワードに入れているのだけれども、必ず「伊藤真」の書籍情報が送られてくる、別に刑法とか勉強してないから