Skip to content

Instantly share code, notes, and snippets.

@a2ikm
Created August 21, 2022 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a2ikm/587ccc4b3755eaaa1b52bdb1e916be2b to your computer and use it in GitHub Desktop.
Save a2ikm/587ccc4b3755eaaa1b52bdb1e916be2b to your computer and use it in GitHub Desktop.
Convert CSV exported from Raindrop to Delcious XML format
#!/usr/bin/env ruby
# c.f. https://github.com/domainersuitedev/delicious-api/blob/master/api/posts.md#v1postsall
#
# <posts tag="" user="user">
# <post href="http://www.weather.com/" description="weather.com"
# hash="6cfedbe75f413c56b6ce79e6fa102aba" tag="weather reference"
# time="2005-11-29T20:30:47Z" />
# ...
# <post href="http://www.nytimes.com/"
# description="The New York Times - Breaking News, World News & Multimedia"
# extended="requires login" hash="ca1e6357399774951eed4628d69eb84b"
# tag="news media" time="2005-11-29T20:30:05Z" />
# </posts>
require "csv"
begin
require "rexml"
rescue LoadError
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "rexml"
end
end
USAGE = <<~USAGE
#{File.basename($0)} <csv>
USAGE
path = ARGV[0]
if path.nil?
$stderr.puts USAGE
abort
end
if !File.exist?(path)
$stderr.puts "#{path} doesn't exist"
abort
end
items = []
CSV.foreach(path, headers: true) do |row|
items << {
"description" => row["title"],
"extended" => "",
"href" => row["url"],
"tag" => (row["tags"] || "").split(", ").join(" "),
"time" => row["created"],
"hash" => "",
}
end
doc = REXML::Document.new
doc.context[:attribute_quote] = :quote
posts = REXML::Element.new("posts", doc, doc.context)
posts.add_attributes("tags" => "", "user" => "")
items.each do |item|
post = REXML::Element.new("post", posts, posts.context)
post.add_attributes(item)
end
doc.write($stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment