Skip to content

Instantly share code, notes, and snippets.

@CvX
Created January 13, 2011 23:18
Show Gist options
  • Save CvX/778824 to your computer and use it in GitHub Desktop.
Save CvX/778824 to your computer and use it in GitHub Desktop.
LeaguePass is a simple script for importing .opml feeds (eg. from NewsFeed) of Dribbble players' activity.
require 'net/http'
require 'nokogiri'
class LeaguePass
def self.authenticate(login, pass)
@@http = Net::HTTP.new('dribbble.com')
@@resp = @@http.get('/session/new')
@@resp = @@http.post('/session', "login=#{login}&password=#{pass}", {'Cookie' => @@resp.response['set-cookie'].to_s})
end
def self.follow(name)
sleep 5 if @@count % 20 == 19
@@cookie = @@resp.response['set-cookie'].to_s if @@resp.response['set-cookie']
@@resp = @@http.post("/#{name}/followers", '', {'Cookie' => @@cookie })
if @@resp.code == '403'
sleep 10
follow(name)
end
end
def self.import_feeds(path)
xml = File.read(path)
doc = Nokogiri::XML(xml)
@@count = 0
doc.xpath("//opml//body//outline").each do |node|
url = node['xmlUrl']
if url[0..18] == "http://dribbble.com" && url[20..24] != 'tags/'
name = url[20..-11]
puts "#{name}..."
follow(name)
@@count += 1
end
end
puts "\nImported #{@@count} feeds."
end
end
if ARGV.length == 3
LeaguePass::authenticate(ARGV[1], ARGV[2])
LeaguePass::import_feeds(ARGV[0])
else
puts "Usage: ruby LeaguePass.rb [path to opml] [dribbble login] [dribbble password]"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment