Skip to content

Instantly share code, notes, and snippets.

@NeMO84
Last active August 29, 2015 14:07
Show Gist options
  • Save NeMO84/335d8a6069891f0c1a0b to your computer and use it in GitHub Desktop.
Save NeMO84/335d8a6069891f0c1a0b to your computer and use it in GitHub Desktop.
A script to help you import exported bookmarks from delicious back into delicious. It can probably easily be tweaked to work with Safari, Chrome, Firefox HTML exports.
#!/bin/ruby
require 'www/delicious'
require 'nokogiri'
require 'cgi'
module WWW
class Delicious
class Post < Element
def title
@title.gsub("—", "-").gsub("æ", "ae").gsub("í", "i")
.gsub("·", "*").gsub("•", "*").gsub(" ", " ") # <-- first param is not empty char for gsub
end
def shared
"no" if @shared == "no" or @shared == false
end
def tags
@tags.respond_to?(:join) ? @tags.join(",") : @tags
end
def to_params()
params = {}
params[:url] = url
params[:description] = title
params[:extended] = notes if notes
params[:shared] = shared
params[:tags] = tags
params[:replace] = replace
params[:dt] = WWW::Delicious::TIME_CONVERTER.call(time) if time
params
end
end
end
end
delicious = WWW::Delicious.new(ENV["username"], ENV['password'])
page = Nokogiri::HTML(open("delicious.html"))
page.css('dt a').each do |a|
data = {
title: a.text,
url: a.attributes['href'].value,
tags: a.attributes['tags'].value
}
data[:shared] = false if a.attributes['private'].value == "1"
puts data
delicious.posts_add(WWW::Delicious::Post.new(data))
puts "done", nil
end
@NeMO84
Copy link
Author

NeMO84 commented Oct 18, 2014

My use case was that I wanted to switch the account that I had initially created with another account I am grouping everything under.

Had to monkey patch the www-delicious gem as it wasn't setting the title, tags, and shared status properly per API Specs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment