Created
February 6, 2009 10:31
-
-
Save pager/59321 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
# "Каких фидов с planetrubyonrails.com ещё нет у меня?" | |
# ./planetror-feeds.rb [<my-exported-subscriptions.opml>] | |
# Выдаёт в STDOUT OPML | |
%w(rubygems nokogiri open-uri timeout socket).each { |d| require d } | |
module OpenUriBroken; end | |
[Errno::EINVAL, Errno::ECONNRESET, SocketError, | |
EOFError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, | |
Timeout::Error, OpenURI::HTTPError ].each {|m| m.send(:include, OpenUriBroken) } | |
planetror_feeds = Nokogiri::HTML(open('http://www.planetrubyonrails.com/pages/channels')). | |
css('div.post > table > tr > td > a').map { |link| | |
begin | |
uri = URI.parse(link['href']); | |
link = Nokogiri::HTML(uri).css('head > link[rel=alternate]').first | |
link = link['href'] if link | |
link[0..3] = 'http' if link && link[0..3] == 'feed' | |
link = "http://"+uri.host+link if link && !(link =~ /^http/) | |
link | |
rescue OpenUriBroken, TypeError => e | |
nil | |
end | |
}.compact | |
my_feeds = ARGV[0] ? Nokogiri::XML(File.read(ARGV[0])).css('outline').map { |feed| feed['xmlUrl'] } : [] | |
puts '<?xml verison="1.0" encoding="UTF-8"?>' | |
puts '<opml version="1.1">' | |
puts '<head></head><body>' | |
(planetror_feeds - my_feeds).each do |xml_url| | |
puts "<outline xmlUrl=\"#{xml_url}\" />" | |
end | |
puts "</body></opml>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment