Skip to content

Instantly share code, notes, and snippets.

@raucao
Created December 24, 2010 07:51
Show Gist options
  • Save raucao/754015 to your computer and use it in GitHub Desktop.
Save raucao/754015 to your computer and use it in GitHub Desktop.
Copy all unread items from RIL to Instapaper
#!/usr/bin/env ruby
require 'rubygems'
require 'ostruct'
require 'httparty'
STDOUT.sync = true
AppConfig = OpenStruct.new
AppConfig.api_key = "key"
AppConfig.ril_username = "username"
AppConfig.ril_password = "password"
AppConfig.ip_username = "email"
AppConfig.ip_password = "password"
class ReadItLater
include HTTParty
format :json
def initialize
@auth = { :username => AppConfig.ril_username, :password => AppConfig.ril_password, :apikey => AppConfig.api_key }
end
def reading_list
self.class.get( "https://readitlaterlist.com/v2/get",
:query => @auth.merge({ :state => "unread", :format => "json" })
)["list"]
end
end
class Instapaper
include HTTParty
format :json
def initialize
@auth = { :username => AppConfig.ip_username, :password => AppConfig.ip_password }
end
def add(item)
self.class.post( "https://www.instapaper.com/api/add",
:basic_auth => @auth,
:query => { :title => item["title"], :url => item["url"] }
)
end
end
puts "Downloading unread items..."
reading_list = ReadItLater.new().reading_list
sorted_list = reading_list.sort{ |a, b| a[1]["time_updated"].to_i <=> b[1]["time_updated"].to_i }.collect!{ |i| i[1] }
instapaper = Instapaper.new
puts "done\n"
puts "Starting export of #{sorted_list.length} unread items...\n"
sorted_list.each do |item|
begin
instapaper.add(item)
print "\e[32m.\e[0m"
rescue
print "\e[31m.\e[0m"
end
end
puts "\ndone\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment