「自動フォロー返し(Ruby bot)2」の編集履歴(バックアップ)一覧に戻る
- #! /usr/bin/ruby
- # encoding: utf-8
-
- # http://route477.net/w/?RubyTwitterJa
-
- require "time"
- require "rubygems"
- require 'twitter'
-
- #http://d.hatena.ne.jp/tondol/20100412/1271016565
-
- def fetch(instance, method, array_name, query)
- next_cursor = -1
- begin
- query['cursor'] = next_cursor
- instance.__send__(method, query).each{|a|
- value = a.pop
- key = a.pop
- if key == array_name then
- value.each{|v|
- yield(v)
- }
- elsif key == "next_cursor" then
- next_cursor = value.to_i
- end
- }
- end while next_cursor > 0
- end
-
- # ログイン
- Twitter.configure do |config|
- config.consumer_key = '???????????????????????'
- config.consumer_secret = 'あばばっばばばばっb'
- config.oauth_token = 'くぁwさえらsdfふじこあsdkふぁks'
- config.oauth_token_secret = 'ajgiswejfij'
- end
-
- f1 = File::open("followers.txt", "r") # http://goo.gl/k0ZNZ
- f2 = File::open("followers_temp.txt", "w")
-
-
- # 自身のfollowersを全件取得して表示
- fetch(Twitter, :followers, "users", {}) {|v|
- f2.puts "#{v.id}"
- }
-
- #followers = Twitter.follower_ids(query={})
- #f2.print("#{followers.ids}") #この方法でフォロワー取得出来ればいいんだけど、id がつながってしまう。
- f2.close
-
- f3 = File::open("followers_temp.txt", "r")
-
- j = 0
- tmp = []
- while tmp[j] = f3.gets
- # print tmp[j]
- j += 1
- end
-
- followers = []
- x = 0
- while followers[x] = f1.gets
- # print followers[x]
- x += 1
- end
- #tmp[]は現在のフォロワー、followers[]は前回のフォロワーが入った配列。
- #それらを比較してtmpだけに入っているIDをフォローする。
- k=0
- i = 0
- q = 9999
-
- while k < j+1
- while i < q
- if followers[i] != nil
- if tmp[k] == followers[i]
- puts "You already follow the user of id: #{tmp[k].to_i}."
- puts "This is in if tmp[k] == followers[i] i=#{i}, k=#{k}"
- i = 0
- break
- end
- else
- if tmp[k] != nil
- puts "You have a new follower of id:#{tmp[k].to_i}. Let's follow."
- puts "This is in if tmp[k] != nil i=#{i}, k=#{k}"
- Twitter.friendship_create(tmp[k].to_i)
- i = 0
- break
- else
- break
- end
- end
- i += 1
- end
- k += 1
- end
- f1.close
-
- print j
-
- f4 = File::open("followers.txt", "w")
- i =0
- while i < j+1
- f4.puts "#{tmp[i]}"
- i += 1
- end
-
- f4.close
- f3.close
-