Created
February 16, 2014 10:34
-
-
Save f440/9032243 to your computer and use it in GitHub Desktop.
Import to ElasticSearch from Pinboard
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
#!/usr/bin/env ruby | |
require 'rexml/document' | |
require 'elasticsearch' | |
doc = REXML::Document.new(open(ARGV[0]).read) | |
es = Elasticsearch::Client.new log: true | |
doc.elements.each('/posts/post') do |element| | |
# attributes: [href, time, description, extended, tag, hash, shared] | |
next if element.attributes["shared"] | |
es.create index: "bookmark", | |
type: "bookmark", | |
body: { | |
url: element.attributes["href"], | |
description: element.attributes["description"], | |
time: DateTime.parse(element.attributes["time"]).iso8601, | |
tag: element.attributes["tag"].split | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment