|
Revision 29031, 1.6 kB
(checked in by hsbt, 5 months ago)
|
|
replace https to http.
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/usr/bin/env ruby |
|---|
| 2 | |
|---|
| 3 | require 'open-uri' |
|---|
| 4 | require 'net/https' |
|---|
| 5 | require 'yaml' |
|---|
| 6 | require 'pathname' |
|---|
| 7 | require 'rubygems' |
|---|
| 8 | require 'pit' |
|---|
| 9 | require 'json' |
|---|
| 10 | |
|---|
| 11 | Net::HTTP.version_1_2 |
|---|
| 12 | |
|---|
| 13 | TWITTER_API = URI("http://twitter.com/") |
|---|
| 14 | |
|---|
| 15 | twitter_account = Pit.get(TWITTER_API.host, :require => { |
|---|
| 16 | :username => 'Please set your username for Twitter.', |
|---|
| 17 | :password => 'Please set your password for Twitter.', |
|---|
| 18 | }) |
|---|
| 19 | |
|---|
| 20 | followers = [] |
|---|
| 21 | begin |
|---|
| 22 | page = 1 |
|---|
| 23 | yaml = YAML.load(Pathname.new(ARGV[0] || "defaults.yaml").expand_path.read) |
|---|
| 24 | |
|---|
| 25 | loop do |
|---|
| 26 | json = JSON.parse(open(TWITTER_API + "statuses/friends.json?page=#{page}", :http_basic_authentication => [twitter_account[:username], twitter_account[:password]]).read) |
|---|
| 27 | break if json.empty? |
|---|
| 28 | |
|---|
| 29 | json.each do |user| |
|---|
| 30 | next if user["status"].nil? |
|---|
| 31 | duration = Time.now - Time.parse(user["status"]["created_at"]) |
|---|
| 32 | followers << user["screen_name"] if duration > yaml["duration"].to_i * 24 * 60 * 60 |
|---|
| 33 | end |
|---|
| 34 | |
|---|
| 35 | page += 1 |
|---|
| 36 | sleep(5) |
|---|
| 37 | end |
|---|
| 38 | |
|---|
| 39 | puts "remove users: #{followers.join(" ")}" |
|---|
| 40 | |
|---|
| 41 | followers.each do |name| |
|---|
| 42 | req = Net::HTTP::Delete.new( "#{TWITTER_API.path}friendships/destroy/#{name}.json", '' ) |
|---|
| 43 | req.basic_auth twitter_account[:username], twitter_account[:password] |
|---|
| 44 | http = Net::HTTP.new( TWITTER_API.host, TWITTER_API.port ) |
|---|
| 45 | if TWITTER_API.scheme == "https" |
|---|
| 46 | http.use_ssl = true |
|---|
| 47 | http.verify_mode = OpenSSL::SSL::VERIFY_NONE # OOPS! |
|---|
| 48 | end |
|---|
| 49 | http.start do |
|---|
| 50 | response = http.request(req) |
|---|
| 51 | case response |
|---|
| 52 | when Net::HTTPOK # 200 |
|---|
| 53 | puts "#{name} is removed." |
|---|
| 54 | when Net::HTTPBadRequest # 400 |
|---|
| 55 | puts "BAD REQUEST: #{name}" |
|---|
| 56 | end |
|---|
| 57 | end |
|---|
| 58 | sleep(15) |
|---|
| 59 | end |
|---|
| 60 | rescue => e |
|---|
| 61 | puts e |
|---|
| 62 | end |
|---|