Last active
August 29, 2015 14:07
-
-
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.
This file contains hidden or 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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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