Created
July 1, 2013 03:00
-
-
Save bferg/5898103 to your computer and use it in GitHub Desktop.
Create Feed Wrangler "smart streams" matching your Google Reader folders. First import your feeds from Google Reader, export your Reader OPML file to the script directory, edit the script to include your user name and password, then run it. Note Feed Wrangler has since added this feature, so this script should no longer be necessary!
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 | |
require 'bundler/setup' | |
require 'opml_saw' | |
require 'json' | |
require 'net/https' | |
require 'uri' | |
# | |
# Enter your email and password for feedwrangler below | |
# | |
user_email = "YOUR EMAIL HERE" | |
password = "YOUR PASSWORD HERE" | |
# Gemfile: | |
# source 'https://rubygems.org' | |
# gem 'nokogiri' | |
# gem 'opml_saw', :git => "git://github.com/feedbin/opml_saw.git", :branch => "master" | |
# | |
# subscriptions.xml is the OPML file from Google Reader Takeout | |
# Extract it and put it in the same directory you run this script from. | |
# | |
file = File.open('subscriptions.xml', 'r') | |
contents = file.read | |
opml = OpmlSaw::Parser.new(contents) | |
opml.parse | |
folders = {} | |
opml.feeds.each do |feed| | |
if feed.has_key? :tag | |
unless folders.has_key? feed[:tag] | |
folders[feed[:tag]] = [] | |
end | |
folders[feed[:tag]].push feed[:xml_url] | |
end | |
end | |
site = Net::HTTP.new("feedwrangler.net", 443) | |
site.use_ssl = true | |
uri = "/api/v2/users/authorize?email=#{user_email}&password=#{URI.escape(password)}&client_key=7d321aef757b8f6e83e39041e37738ec" | |
response = site.get2(uri) | |
token = "" | |
if response.code == "200" | |
fwfeeds = JSON.parse(response.body) | |
token = fwfeeds["access_token"] | |
else | |
puts "Unable to retrieve subscription list from feedwrangler.net: #{response.code} #{response.message}" | |
response.each { |key, val| printf "%-14s = %-40.40s\n", key, val } | |
p response.body[400, 55] | |
exit | |
end | |
feedindex = {} | |
fwfeeds["feeds"].each do |feed| | |
feedindex[feed["feed_url"]] = feed["feed_id"] | |
end | |
folders.each do |name, feedurls| | |
feedids = [] | |
feedurls.each do |feedurl| | |
if feedindex.has_key? feedurl | |
feedids.push feedindex[feedurl] | |
end | |
end | |
folders[name] = feedids | |
end | |
folders.each do |name, feedids| | |
uri = "/api/v2/streams/create?access_token=#{token}&title=#{URI.escape(name)}&only_unread=true&all_feeds=false&feed_ids=#{feedids.join(',')}" | |
response = site.get2(uri) | |
puts "Create \"#{name}\": #{response.code} #{response.message}" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment