import bookmarks to pocket from delicious

  1. Export your bookmarks here: https://del.icio.us/export
  2. Create a pocket app and get the consumer key: https://getpocket.com/developer/apps/
  3. Get an access_token by following the instructions here https://getpocket.com/developer/docs/authentication or following these steps:
curl -d "consumer_key=<YOUR_CONSUMER_KEY>&redirect_uri=https://requestb.in/ssgptyss" -X POST https://getpocket.com/v3/oauth/request

Take note of the request token, then follow this URL with a browser to authorize your app:

https://getpocket.com/auth/authorize?request_token=<THE_REQUEST_TOKEN>&redirect_uri=https://requestb.in/ssgptyss

To inspect the redirection, go to https://requestb.in/ssgptyss?inspect

Then issue this command

curl -d "consumer_key=<YOUR_CONSUMER_KEY>&code=<THE_REQUEST_TOKEN>" -X POST https://getpocket.com/v3/oauth/authorize

And take note of the access_token.

Then you can execute this code

require 'uri'
require 'net/https'
require 'json'
require 'nokogiri'

url = URI("https://getpocket.com/v3/add")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'

doc = File.open("<GET_THIS_FILE_EXPORTING_YOUR_BOOKMARKS_ON_DELICIOUS>") { |f| Nokogiri::XML(f) }
doc.xpath("//DT//A").each do |entry|
  href = entry.attributes["HREF"].value
  tags = entry.attributes["TAGS"].value
  isPrivate = entry.attributes["PRIVATE"].value == "1"

  if tags.downcase.include?("wine")
    puts "✖ skipping unwanted #{href} because of #{tags}"
  elsif isPrivate
    puts "✖ skipping private #{href}"
  else
    begin
      uri = URI(href)
      response = Net::HTTP.get_response(uri)
      if response.code == "301" || response.code == "302"
        response = Net::HTTP.get_response(URI.parse(response.header['location']))
      end
      if (response.code[0] == "2")
        item = {
          url: href,
          tags: tags.split(",").delete_if{|e| e.start_with?("for:")}.push("delicious").join(","),
          consumer_key: "<CREATE_A_POCKET_APP_TO_GET_THIS_KEY>",
          access_token: "<GET_THIS_TOKEN_WITH_AN_AUTHORIZE_REQUEST>"
        }
        request.body = JSON.generate(item)

        pocket_response = http.request(request)
        puts "✓ #{href} - #{pocket_response.code}"
      else
        puts "✖ skipping #{href}: #{response.code}"
      end
    rescue Exception => e
      puts "☠ #{href} because of #{e}"
    end
  end
end