--- layout: old_post title: いつも読んでるRSSの持ち主をtako3.comとfooo.nameから探してTwitterでFollow permalink: /tatsuya/show/403-rss-tako3-com-fooo-name-twitter-follow ---

ちょっと面白かった。

いつも読んでる人を follow - Elementary

まずLDRで購読してるRSSをOPMLでエクスポート、次に tako3.comfooo.name からURL全件取得。OPMLとJSONをパースしてtwitterのアカウントを探して一括Follow。
良いな〜、面白そうなので真似してみる。

まずLDRからOPMLエクスポート、全部ってのは多すぎるのでレート "5" のフィードのみに絞った。
この方法を使った http://d.hatena.ne.jp/margin/20070707/livedoor_reader_fastladder_rate

あとはRubyでパース、パース、パース
レート 5 のフィードが160個くらい、うちTwitterのアカウントが見つかったのが50人くらいだった。(むむ、もっとデータを充実する必要があるな>fooo.name)
でTwitterAPIから大量Follow :)すでにFollowしてる人はエラーになる、結果25人くらい。

こんな感じでやりました。

require "rexml/document"
require "open-uri"
require "net/http"

opml_name = "export.xml" #Download from LDR!!
tako3 = "http://tako3.com/json/all"
fooo = "http://fooo.name/tako3/json/all"

twitter_path = "/friendships/create"
twitter_account = "USERID" #twitter account
twitter_password = "PASSWORD" #twitter password

#opml to twitter url---------------------------------------------------------------
twitt_maps = {}
[tako3, fooo].each do |name|
  open(name) do |file|
    file.each_line do |line|
      urls = line.scan(/"(.*)"/)[0][0].split(" ")
      if twitter_url = urls.find {|url| url =~ Regexp.new("^http://twitter.com/") }
        urls.each do |url|
          twitt_maps[url] = twitter_url
        end
      end
    end
  end
end

opml_twitters = []
REXML::Document.new(open(opml_name)).elements["/opml/body/outline/outline[@title='5']"].each do |element|
  url = element.attributes["htmlUrl"] if element.class == REXML::Element
  opml_twitters << twitt_maps[url].chomp("/").scan(/twitter\.com\/(.*)/)[0][0] if twitt_maps[url]
end
opml_twitters.uniq!

#do post to twitter----------------------------------------------------------------
opml_twitters.each do |name|
  req = Net::HTTP::Post.new("#{twitter_path}/#{name}.xml")
  req.basic_auth twitter_account, twitter_password
  Net::HTTP.start("twitter.com", 80) do |http|
    res = http.request(req)
    p res.body
  end
end