Coming from the Rails world I thought would do the right thing and DRY it up with a little script. So little it will fit right here for the world to grab:
google_user = "XXXXXXXX"
google_pw = "XXXXXX"
twitter_user = "XXXXXXX"
twitter_pw = "XXXXXXX"
session = GoogleSpreadsheet.login(google_user, google_pw)
ws = session.spreadsheet_by_key("p3LA_Q08eM-VAAyq03ZSjYQ").worksheets[0]
base = Twitter::Base.new(twitter_user, twitter_pw)
(1..1000).each do |row|
url = ws[row,2]
matched_user = url.match(/http:\/\/.*twitter.com\/(.*)/)
next unless matched_user
matched_user = matched_user[1]
puts "Attmepting to follow "
begin
base.create_friendship(matched_user)
puts "success"
rescue
puts "******* Failed "
end
end
You can grab the code from github at http://github.com/digidigo/iphone-dev-tweeters-/tree/masterYou will need to grab a few ruby gems to make this work. Check out the google spreadsheet gem at http://github.com/gimite/google-spreadsheet-ruby/tree/master . And then the twitter gem at http://twitter.rubyforge.org/rdoc/
So go out there and be crazy like me and see what all of us Iphone devs are tweeting about.
If you get an error like this:
ERROR: Error installing twitter: echoe requires RubyGems version >= 1.2
You will need to update your rubygems. gem update --system should do the trick.
15 comments:
Most twitter following I've ever done, in the space of about 30 seconds
Hey Charlie.. Me too... Figured I better follow everyone tonight before the scammers/spammers find the list.
i dont get it... how do you do it?
pretty cool; got me 200 or so new friends... i had some issues on windows machine w/ json incompatibility. rather than futz w/ that - did this w/o need for twitter gem culprit:
session = GoogleSpreadsheet.login(google_user, google_pw)
ws = session.spreadsheet_by_key("p3LA_Q08eM-VAAyq03ZSjYQ").worksheets[0]
(1..10).each do |row|
url = ws[row,2]
matched_user = url.match(/http:\/\/twitter.com\/(.*)/)
next unless matched_user
matched_user = matched_user[1]
puts "Attmepting to follow #{matched_user}"
begin
url = URI.parse("http://twitter.com/friendships/create/#{matched_user}.xml")
req = Net::HTTP::Post.new(url.path)
req.basic_auth twitter_user, twitter_pw
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
case res
when Net::HTTPSuccess
puts "Sweet"
else
raise res.error!
end
rescue
puts "******* Failed #{$!.message}"
end
end
Nice work Dave. Love your work. There'll be a few more peeps for you to follow when you wake up - over 200 now.
Had an issue installing Twitter gem on OS X 10.5, was giving
"ERROR: Error installing twitter:
echoe requires RubyGems version >= 1.2"
Solution to the problem here: http://www.ruby-forum.com/topic/171275
Thanks for making the script!
Thanks for putting up this script!
Had to update gems, but worked like a charm (MacOS 10.5). Fantastic job man, kudos!
I got it all running under Windows Vista (a pain let me tell you), but there seems to be a problem now, maybe Twitter changed something:
Attmepting to follow yuichiro
******* Failed Twitter is returning a 411: Length Required
How do I fix this?
nice post
I couldn't get this script to work for a while because the 'Twitter' Gem was updated to support oAuth.
To get around this you need to install an older version (command: gem install twitter -v 0.4.1) of the gem.
Then you need to edit the code. Insert the line gem 'twitter','=0.4.1' just above the line that says require "twitter"
This will only work as long as Twitter allows Basic Auth to exist. Twitter says it will not last forever.
I'll be sure to bookmark your blog
Looks like the loop only goes to 1000, but there's 1054 entries on it now! ;) I don't know if people want to follow that many folks, but needs to be upped I think.
After I updated to the latest Twitter version I had to change a few lines to work with the new API:
# For authorization
httpauth = Twitter::HTTPAuth.new(twitter_user, twitter_pw)
base = Twitter::Base.new(httpauth)
and then:
#base.create_friendship(matched_user)
base.friendship_create(matched_user, true)
So are people still doing this?
There are over 1000 developers now!
OS X I had to run the
sudo gem update rails
sudo gem update --system
AFTER A REBOOT
Then,
gem sources -a http://gems.github.com
sudo gem install gimite-google-spreadsheet-ruby
sudo gem install twitter
Post a Comment