-
-
Save toluju/744312 to your computer and use it in GitHub Desktop.
require 'net/http' | |
require 'uri' | |
require 'cgi' | |
text = "<html><head><title>Delicious2Google</title></head><body>" + | |
"<h1>Upload</h1>" + | |
"<form action='https://www.google.com/bookmarks/mark?op=upload&zx=#{rand(65535)}' method='POST'>" + | |
"<input type='submit'/><input type='hidden' id='data'></form>" + | |
"<textarea id='xml' style='display:none'>\n<bookmarks>" | |
File.open(ARGV[0], "r").each_line do |line| | |
match = line.match(/<DT><A HREF="(.*)" ADD_DATE="(.*)" PRIVATE="(.*)" TAGS="(.*)">(.*)<\/A>/) | |
if match | |
link = CGI::escapeHTML(match[1].split("?")[0].split("#")[0]) | |
date = CGI::escapeHTML(match[2]) | |
tags = match[4].split(",").map! do |t| CGI::escapeHTML(t) end | |
title = CGI::escapeHTML(match[5]) | |
text += "<bookmark><url>#{link}</url><title>#{title}</title>" + | |
"<labels><label>#{tags.join(",")}</label></labels></bookmark>" | |
end | |
end | |
text += "</bookmarks>\n</textarea>" | |
text += <<eos | |
<script type='text/javascript'> | |
var src = document.getElementById('xml'); | |
var tgt = document.getElementById('data'); | |
tgt.name = "<?xml version"; | |
tgt.value = '"1.0" encoding="utf-8"?>' + src.value; | |
</script> | |
eos | |
text += "</body><html>" | |
File.new(ARGV[1], "w").puts text |
Yes, sorry, should have added that!
it doesn't work for me, I've 1364 bookmarks in Delicous and it import only the 233 last bookmarks :-(
Can you share the 234th bookmark? I've discovered that Google Bookmarks doesn't accept certain URLs, so once it encounters a URL it doesn't like, it just drops the rest. That's why I'm trimming off the query string and the hash fragment, because those two were already causing problems - it appears there are other ways to make Google Bookmarks choke as well.
Awesome script... but it think this delicious api xml method doesn't support youtube delicious bookmarks since they all have question marks in them... http://www.youtube.com/watch?v=eUB4j0n2UDU
Right, I'm stripping query strings because it appeared the Google Bookmarks API was rejecting URLs with query strings. It could be the error lies elsewhere, but I couldn't find much documentation.
http://lnkr.mobi/bm/google_bookmarks_api/ seems to says that "upload capability was written to migrate "IE favorites" to Google Bookmarks, and IE favorites don't have annotations.". So I wonder if it's better to have the script find all delicious bookmarks that don't have notes/comments and continue to use the xml approach.. and for the others use the http://www.google.com/bookmarks/mark api call for each entry.
Google now has an official delicious bookmarks importer: https://www.google.com/bookmarks/deliciousimport
Note: Main idea and some of the code borrowed from http://persistent.info/delicious2google/
Usage
ruby delicious2google.rb <html file from export> <output file>
<output file>
in your browser, hit submit.TODO: