Created
March 30, 2014 11:41
-
-
Save f440/9871599 to your computer and use it in GitHub Desktop.
Import from delicious to 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 'nokogiri' | |
| require 'date' | |
| require 'faraday' | |
| html = Nokogiri::HTML(open("delicious.html")) | |
| posts = [] | |
| html.xpath("//dd | //dt").each do |element| | |
| if element.name == 'dt' | |
| post = { | |
| url: element.css('a').attribute("href").inner_text, | |
| description: element.css('a').children.first.text, | |
| dt: Time.at(element.css('a').attribute("add_date").value.to_i).strftime("%Y-%m-%dT%H:%M:%S%z"), | |
| private: element.css('a').attribute("private").value == 0 ? 'yes' : 'no', | |
| tags: element.css('a').attribute("tags").value.split(",").join(' '), | |
| replace: "yes" | |
| } | |
| posts << post | |
| else | |
| posts[-1][:extended] = element.text.chomp | |
| end | |
| end | |
| conn = Faraday.new(url: 'https://api.pinboard.in') do |faraday| | |
| faraday.request :url_encoded | |
| faraday.response :logger | |
| faraday.adapter Faraday.default_adapter | |
| end | |
| posts.each_with_index do |body, i| | |
| puts "Processing: #{i}" | |
| response = conn.get do |req| | |
| req.url '/v1/posts/add' | |
| req.params[:auth_token] = 'USER:TOKEN' | |
| body.each{ |k, v| req.params[k] = v } | |
| end | |
| puts response.status | |
| puts response.body | |
| sleep 3 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment