Show
Ignore:
Timestamp:
10/13/08 20:59:05 (3 months ago)
Author:
hsbt
Message:

used POST method.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/misc/twitter_remove_friends/twitter_remove_friends_json.rb

    r15139 r21250  
    22 
    33require 'open-uri' 
     4require 'net/http' 
    45require 'yaml' 
    56require 'pathname' 
     
    78require 'pit' 
    89require 'json' 
     10 
     11Net::HTTP.version_1_2 
    912 
    1013TWITTER_API = URI('http://twitter.com/') 
     
    2326                json = JSON.parse(open(TWITTER_API + "statuses/friends.json?page=#{page}", :http_basic_authentication => [twitter_account[:username], twitter_account[:password]]).read) 
    2427                break if json.empty? 
    25                  
     28 
    2629                json.each do |user| 
     30                   next if user["status"].nil? 
    2731                        duration = Time.now - Time.parse(user["status"]["created_at"]) 
    2832                        followers << user["screen_name"] if duration > yaml["duration"].to_i * 24 * 60 * 60 
     
    3640         
    3741        followers.each do |name|  
    38                 next if yaml["ignore"].include?(name) 
    39                 open(TWITTER_API + "friendships/destroy/#{name}.xml", :http_basic_authentication => [twitter_account[:username], twitter_account[:password]]) 
    40                 puts "#{name} is removed" 
    41                 sleep(10) 
     42                req = Net::HTTP::Post.new( "/friendships/destroy/#{name}.json", '' ) 
     43                req.basic_auth twitter_account[:username], twitter_account[:password] 
     44                Net::HTTP.start( TWITTER_API.host ) do |http| 
     45                        response = http.request(req) 
     46                        puts "#{name} is removed."  
     47                end 
     48                sleep(15) 
    4249        end 
    4350rescue => e