Skip to content

Instantly share code, notes, and snippets.

@kalv
Created August 20, 2009 16:32
Show Gist options
  • Save kalv/171177 to your computer and use it in GitHub Desktop.
Save kalv/171177 to your computer and use it in GitHub Desktop.
desc "Subscribe a number of feeds to a superfeedr account"
task :subscribe_superfeedr do
Superfeedr.connect(Tfweb.conf[:superfeedr_jid], Tfweb.conf[:superfeedr_password]) do
puts "Connected to superfeedr"
pos = 0
batch_size = 100
loop do
feeds = Feed.find(:all, :select=>["feedurl, id"], :limit=>batch_size, :offset=>pos, :conditions=>{:superfeedr=>false})
if feeds.count == 0
puts "broke loop at pos=#{pos}"
break
end
Superfeedr.subscribe(feeds.collect(&:feedurl)) do |result|
if result
Tfweb::DB.check_connection
Tfweb::DB.connection.execute("UPDATE feeds SET superfeedr = true WHERE id IN (#{feeds.collect(&:id).join(",")})")
puts "subscribed #{result.size}"
else
puts "Could not feed #{feed.feedurl}"
end
end
pos+=batch_size
end
end
end
desc "Unsubscribe feeds from superfeedr account"
task :unsubscribe_superfeedr do
Superfeedr.connect(Tfweb.conf[:superfeedr_jid], Tfweb.conf[:superfeedr_password]) do
puts "Connected to superfeedr"
pos = 0
batch_size = 100
loop do
feeds = Feed.find(:all, :select=>["feedurl, id"], :limit=>batch_size, :offset=>pos, :conditions=>{:superfeedr=>true})
if feeds.count == 0
break
end
Superfeedr.unsubscribe(feeds.collect(&:feedurl)) do |result|
if result
Tfweb::DB.check_connection
Tfweb::DB.connection.execute("UPDATE feeds SET superfeedr = false WHERE id IN (#{feeds.collect(&:id).join(",")})")
puts "unsubscribed #{result.size}"
else
puts "Could not feed #{feed.feedurl}"
end
end
pos+=batch_size
end
end
end
desc "list feeds on superfeedr"
task :list_on_superfeedr do
@page = 0
Superfeedr.connect(Tfweb.conf[:superfeedr_jid], Tfweb.conf[:superfeedr_password]) do
puts "connected to superfeedr... will list 200 pages and count feeds"
#EventMachine::add_periodic_timer(1) do
loop do
@page += 1
Superfeedr.subscriptions_by_page(@page) do |page, feeds|
#puts "page=#{page} feeds=#{feeds.size}"
SuperfeedrResponse::add_feeds(feeds)
end
if @page > 200
puts "sent 200 page requests"
break
end
end
EventMachine::add_periodic_timer(10) do
puts "After 10 secs - Total Feeds pulled from pages so far count=#{SuperfeedrResponse.feeds.size} uniq=#{SuperfeedrResponse.feeds.uniq.size}"
#puts SuperfeedrResponse.feeds.inspect
end
#end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment