Skip to content

Instantly share code, notes, and snippets.

@icyleaf
Created December 16, 2013 06:44
Show Gist options
  • Save icyleaf/7983194 to your computer and use it in GitHub Desktop.
Save icyleaf/7983194 to your computer and use it in GitHub Desktop.
Google Reader "subscriptions.json" file to opml: ruby json_to_opml.rb /to/your/subscriptions.json > /to/your/saved/path
require 'multi_json'
require 'builder'
data = File.new(ARGF[0])
json = MultiJson.load(data)
feeds = {}
json["subscriptions"].each do | item |
item["categories"].each do |cat|
cat_name = cat["label"]
feeds[cat_name] = [] if !feeds.has_key?(cat_name)
feeds[cat_name].push({
:type => 'rss',
:title => item["title"],
:text => item["title"],
:htmlUrl => item["htmlUrl"],
:xmlUrl => item["id"].gsub("feed/", "")
})
end
end
xml = Builder::XmlMarkup.new(:target => STDOUT, :indent => 4)
xml.instruct!
xml.opml(:version => 1.0) do
xml.head do
xml.title "icyleaf's feeds on Google Reader"
end
xml.body do
feeds.each do | cat, items |
xml.outline(:text => cat, :title => cat) do
items.each do |item|
xml.outline(item)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment