It seems that Blinklist’s JSON export doesn’t work any more, and delicious now requires OAuth authentication for new accounts (which rubilicious doesn’t support). So I created another script to transform Blinklist’s CSV format to HTML bookmark format which you can import to delicious.
It´s done. I was suffering constant problems with BlinkList and I decided to move to del.icio.us. I also decided to rescue the old powermarks 3.5 bookmarks from the oblivion and import them to del.icio.us too.
BlinkList gives you the option of exporting your bookmarks in JSON format via the Options ->Export links. (here is the link)
So grab the json file and save it somewhere in your disk.
Then you have to use the script below to load the bookmars into del.icio.us but first make sure that you have ruby or jruby, rubygems, json-jruby or json-ruby, jruby-openssl and rubilicious installed.
If you use jruby you can install everything in the following way:
jruby -S gem install json-jruby jruby-openssl rubilicious-0.2.0.gem
Then use the following script to load all the bookmarks in the json file to del.icio.us. Just change the filename and username and password to suit your needs.
#!/usr/bin/ruby require "rubygems" require "rubilicious" require "json" require "date" require "time" def getTime(item) dateadd = item['dateadd'] return Time.at(dateadd) unless dateadd == false return Time.now end def getIsPrivate(item) isprivate = item['private'] return "checked"==isprivate end def getTags(item) item['tag'].gsub(' ', '_').gsub(',',' ') end json_string = File.new("blinklist20080710.json").read result = JSON.parse(json_string) r = Rubilicious.new('your_delicious_username','your_delicious_password') i=0 for item in result do i += 1 puts "#{i}: #{item['url']}" #next if i < 3229 r.add(item['url'],item['name'],item['description'], getTags(item), getTime(item), true, getIsPrivate(item)) end puts "ended"
If the script fails in the middle of the import don´t worry. just uncomment the “#next if i < 3229" and change the 3229 to the last bookmark id that was loaded. Rerun the script and it will skip all bookmarks up to the one you write there.
Loading the old powermark file into del.icio.us is a little more complex. You will need two files:
1) state_pattern.rb (from maurice codik’s blog). I´m copying it here for completeness sake
2) The script that parses the powermarks file and load it to del.icio.us
(This script will add all the links as private. If you don´t want that behaviour just modify the last parameter in "@context.r.add(@context.url,@context.name,@context.desc, @context.tags, Time.at(@context.date), false, true)" to "false".) Again, if the script fails in the middle of the import don´t worry. just uncomment the "#next unless i > 2261" and change the 2261 to the line number where you want to resume parsing the powermarks file. Rerun the script and it will skip all previous lines. Hope it helps anybody that it´s trying to escape from Blinklist and/or Powermarks. I successfully imported 3299 blinklist bookmarks and 4000 powermarks bookmarks (a lot of dupes though). By the way, the first script will replace any previous bookmark with the same url and the second script will not. That´s the way I wanted it but of course you can change it. The parameter before the last one in the call to add is the one that control the "replace". (see add documentation).#!/usr/bin/ruby
# Copyright (C) 2006 Maurice Codik - maurice.codik@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
# associated documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# an example:
#
# class Connection
# include StatePattern
# state :initial do # you always need a state named initial. this is where you begin.
# def connect
# puts "connected"
# # move to state :connected. all other args to transition_to are passed to the new state's constructor
# transition_to :connected, "hello from initial state"
# end
# def disconnect
# puts "not connected yet"
# end
# end
# state :connected do
# def initialize(msg)
# puts "initialize got msg: #{msg}"
# end
# def connect
# puts "already connected"
# end
# def disconnect
# puts "disconnecting"
# transition_to :initial
# end
# end
# def reset
# puts "reseting outside a state"
# # you can also change the state from outside of the state objects
# transition_to :initial
# end
# end
# how's it work:
# Each call to state defines a new subclass of Connection that is stored in a hash.
# Then, a call to transition_to instantiates one of these subclasses and sets it to the be the active state.
# Method calls to Connection are delegated to the active state object via method_missing.
module StatePattern
class UnknownStateException < Exception
end
def StatePattern.included(mod)
mod.extend StatePattern::ClassMethods
end
module ClassMethods
attr_reader :state_classes
def state(state_name, &block)
@state_classes ||= {}
new_klass = Class.new(self, &block)
new_klass.class_eval do
alias_method :__old_init, :initialize
def initialize(context, *args, &block)
@context = context
__old_init(*args, &block)
end
end
@state_classes[state_name] = new_klass
end
end
attr_accessor :current_state, :current_state_obj
def transition_to(state_name, *args, &block)
new_context = @context || self
klass = new_context.class.state_classes[state_name]
if klass
new_context.current_state = state_name
new_context.current_state_obj = klass.new(new_context, *args, &block)
else
raise UnknownStateException, "tried to transition to unknown state, #{state_name}"
end
end
def method_missing(method, *args, &block)
unless @current_state_obj
transition_to :initial
end
if @current_state_obj
@current_state_obj.send(method, *args, &block)
else
super
end
end
end
#!/usr/bin/ruby
require "rubygems"
require "rubilicious"
require "json"
require "date"
require "time"
require "state_pattern"
class Parser
include StatePattern
attr_accessor :name, :url,:desc,:tags ,:date , :r
state :initial do
def parse(line)
#puts "initial: #{line}"
if line =~ /<a href="(.*)">(.*)< \/a>/
@context.name = $2
@context.url = $1
transition_to :read_keywords
end
end
end
state :read_keywords do
def parse(line)
if line =~ /<!--keywords-->(.*)$/
@context.tags = $1.chomp
transition_to :read_keywords2
end
end
end
state :read_keywords2 do
def parse(line)
#puts "read_keywords2: #{line}"
if line =~ /<!--/
if line =~ /^<!--desc-->/
transition_to :read_desc
@context.current_state_obj.parse(line)
end
if line =~ /^<!--mdata/
transition_to :read_metadata
@context.current_state_obj.parse(line)
end
return
end
@context.tags += " " + line.chomp
end
end
state :read_desc do
def parse(line)
if line =~ /<!--/
if line =~ /<!--desc-->(.*)/
@context.desc = $1.chomp
else
#puts "not desc"
if line =~ /<!--mdata/
transition_to :read_metadata
@context.current_state_obj.parse(line)
else
raise "don´t know how to parse this in this state #{line}"
end
return
end
else
@context.desc += " " + line.chomp
end
end
end
state :read_metadata do
def parse(line)
@context.date = $1.hex if line =~ /<!--mdata=\[\w+\]\[([0-9A-F]+)\]\[([0-9A-F]+)\]\[([0-9A-F]+)\]/
@context.date = Time.now.to_i if @context.date < 0
puts "=============================="
puts "name: #{@context.name}"
puts "url: #{@context.url}"
puts "tags: #{@context.tags}"
puts "date: #{Time.at(@context.date)}"
puts "desc: #{@context.desc}" unless @context.desc.nil?
puts "=============================="
@context.r.add(@context.url,@context.name,@context.desc, @context.tags, Time.at(@context.date), false, true)
@context.name = @context.url = @context.tags = @context.date = @context.desc = nil
transition_to :initial
end
end
end
r = Rubilicious.new('your_delicious_username','your_password')
p = Parser.new
p.r = r;
i = 0
File.new("pm3520070703.htm").each { |line|
puts i;
i += 1
#next unless i >2261
p.parse(line);
}
puts "ended"
</a>







































13 Comments
Hi Reubs, I have been meaning to escape BL for a while now, but I have to say I am pretty muck a nw00t when it comes to ruby and all. So if you are still around, and if it is not too much hassle, could you parse my BL JSON file? Just let me know.
Thanks anyway though
take care.
Hi there,
Just wanted to let you know that i am sorry that we let you guys down. We are working on BlinkList 2.0 and I hope that we can win you back with a much faster and far improved service in the next few months.
Mike
Mike, I have to say that I am surprised (in a good way) of the CR of BL !I’ll wait and see for BL2.0 then. At least for the sake of it :-)
Ruben,
I tried to use the Ruby scripts to load my Powermarks bookmarks into Delicious. It ran to completion (over 7000 bookmarks) but went very fast (a couple of seconds) and no bookmarks were actually added to my Delicious account.
I selected JSON version 1.1 (MSWin32). Should I use a newer version?
Thanks,
JbL
Sorry, it was actually JSON version 1.1.1. I also tried installing the json_pure gem (version 1.1.3), but the same result. It’s like it’s parsing the entire file, but not actually trying to upload anything to delicious.
Help!
JbL
does it show anything on the screen?
Im seeing the same problem that JBL has. Apparto from the number of bookmarks processed, I dont see any other message. I have even tried putting a fake delicious account and the script does not complain. I guess the script is never trying to connect to delicious.
Thanks
If you only see a list of number with no url after those. That means that the URLs in the json file are not being parsed by the JSON module. First check that the JSON file is a proper JSON file. Open it with notepad or vi.
I forgot to mention that I’m trying to export from powermarks so there is no JSON file. I also found out that my powermarks file had some tags in uppercase. adding /i to all the regexps of your coded fixed this.
I’m now getting this error (on the first bookmark)
==============================
name: CRL Toolkit(Information Retrieval)
url: http://crl.nmsu.edu/crltoolkit/crl2.htm
tags: CRL Toolkit Information Retrieval Programming Misc powermarks
date: Mon May 17 16:33:25 CEST 1999
./powermarks2delicious.rb:86:in
add': wrong number of arguments (7 for 5) (ArgumentError)parse’from ./powermarks2delicious.rb:86:in
from ./powermarks2delicious.rb:43:in
parse'method_missing’from ./state_pattern.rb:104:in
from ./powermarks2delicious.rb:104
from ./powermarks2delicious.rb:100
According to the documentation the add function is being called with the right number of parameters. Any clue? (I’m not a Ruby programmer)
Thanks for your help
Are you sure that you installed the right rubilicious version (0.2.0)?
I had installed version 1.4 (which was part of ubuntu). Thanks for your support. I worked like a charm
but blinklist do not export json anymore! :(
in fact, csv is the only way to export something…
maybe can you change it to use the csv output instead the json?
Sorry to hear that they dropped JSON export format. Unfortunately I don’t have time to spend on this. But you could try to modify the ruby ruby scripts in this post to use a CSV parser instead.
As I said I don’t have time to test it myself but you could try something like this
One Trackback
[...] new accounts (now it forces new users to use the OAuth / Yahoo ID). So the solutions described in this old post of mine doesn’t [...]