Skip to content

Instantly share code, notes, and snippets.

@duhanebel
Created September 9, 2011 16:07
Show Gist options
  • Save duhanebel/1206623 to your computer and use it in GitHub Desktop.
Save duhanebel/1206623 to your computer and use it in GitHub Desktop.
Instapaper CSV to Yojimbo importer
require 'rubygems'
require 'rss/1.0'
require 'rss/2.0'
require 'open-uri'
require 'appscript'
require 'syslog'
require 'csv'
require 'uri'
include Appscript
tags = ['instapaper']
yj = app('Yojimbo')
items_added = 0
items_skipped = 0
CSV::Reader.parse(File.open('instapaper-export.csv', 'rb')) do |row|
item_title = row[1]
item_link = "http://www.instapaper.com/text?u=" + URI.escape(row[0])
item_folder = row[-1]
puts "Checking #{item_title} : #{item_link}"
#if it's not already in the libary, then add it
#check the comments field of the item for the original link
if (not yj.collections[its.name.eq("Library")].web_archive_items[its.comments.eq(item_link)].exists)
#Item doesn't exist in the Library, so add it
print "Adding item ", item_link, "\n"
#log "Adding item #{item_link}"
#create new item in Yojimbo
#set the comments field to the original URL from the feed
#many websites normalize the link when saving the web archive
# so Yojimbo's source_url can't be trusted
new_item = yj.make( :new =>:web_archive_item,
:with_contents => item_link,
:with_properties =>{:comments => item_link})
item_tags = Array.new(tags)
item_tags << item_folder
new_item.add_tags(item_tags)
items_added = items_added + 1
else
print "Ignoring existing item ", item_link, "\n";
items_skipped = items_skipped + 1
end
end
print "Added/Skipped #{items_added} / #{items_skipped} items\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment