-
-
Save venj/744857 to your computer and use it in GitHub Desktop.
Add a bookmark count for user to check with delicious. Add some line breaks for the out put file to avoid text editor crash if opened by the curious users with a lot of book marks.
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
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>\n" | |
bookmark_count = 0 | |
File.open(ARGV[0], "r").each_line do |line| | |
match = line.match(/<DT><A HREF="(.*)" ADD_DATE="(.*)" PRIVATE="(.*)" TAGS="(.*)">(.*)<\/A>/) | |
if match | |
bookmark_count += 1 | |
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 += "\t<bookmark><url>#{link}</url><title>#{title}</title>" + | |
"<labels><label>#{tags.join(",")}</label></labels></bookmark>\n" | |
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>" | |
puts "#{bookmark_count} bookmarks exported. \nPlease check to make sure you didn't miss any one. :D" | |
File.new(ARGV[1], "w").puts text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment