-
-
Save julien51/171182 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :subscribe_superfeedr do | |
feeds = Feed.find(:all, :select=>["distinct(feedurl)"], :limit=>2000, :conditions=>{:superfeedr=>false}) | |
Superfeedr.connect(Tfweb.conf[:superfeedr_jid], Tfweb.conf[:superfeedr_password]) do | |
puts "Connected to superfeedr" | |
if feeds.count == 0 | |
EM.stop | |
end | |
Superfeedr.subscribe(feeds.map(&:feedurl) do |result| | |
if result | |
puts "Subscribed #{result.inspect}" | |
Tfweb::DB.check_connection | |
Tfweb::DB.connection.execute("UPDATE feeds SET superfeedr = true WHERE feedurl IN ('#{result.join(', ')}')") | |
else | |
puts "Could not feed #{feed.feedurl}" | |
end | |
end | |
end | |
end | |
task :unsubscribe_all_on_superfeedr do | |
Superfeedr.connect(Tfweb.conf[:superfeedr_jid], Tfweb.conf[:superfeedr_password]) do | |
puts "Connected to superfeedr" | |
EventMachine::add_periodic_timer(3) do | |
Superfeedr.subscriptions(1) do |page, feeds| | |
if feeds.size == 0 | |
EM.stop | |
end | |
feeds.each do |feed| | |
Superfeedr.unsubscribe(feed) do |result| | |
if result | |
#puts "Un-Subscribed #{url}" | |
Tfweb::DB.check_connection | |
Tfweb::DB.connection.execute("UPDATE feeds SET superfeedr = false WHERE feedurl='#{URI.escape(feed)}'") | |
else | |
puts "Could not feed #{feed.feedurl}" | |
end | |
end | |
end | |
puts "unsubscribed #{feeds.size} feeds" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment