class PinboardTools::SafariReadingListImporter

Attributes

tagger[RW]

Public Class Methods

new(args) click to toggle source
# File lib/pinboard_tools/srl_to_pinboard.rb, line 21
def initialize(args)
  @tagger = Tagger.new(tag: nil, verbose: args[:verbose])
end

Public Instance Methods

run() click to toggle source
# File lib/pinboard_tools/srl_to_pinboard.rb, line 25
def run
  links = Array.new

  # from gist: https://gist.github.com/andphe/3232343
  input = %x[/usr/bin/plutil -convert xml1 -o - ~/Library/Safari/Bookmarks.plist | grep -E  -o '<string>http[s]{0,1}:/.*</string>' | grep -v icloud | sed -E 's/<\/{0,1}string>/g']

  input.scan(/(http.+){/).each do |url|
    links.push url.first

    # p link
  end

  pinboard, bar = Pinboard::Client.new(:username => tagger.pb_user, password: tagger.pb_pass), ProgressBar.new(links.size)

  links.reverse_each do |url|
    begin
      meta = tagger.get_metadata(url)

      article = {
        url: url,
        description: meta[:title],
        extended: meta[:excerpt],
        tags: meta[:keywords],
        replace: true,
        toread: true,
        :public => false
      }

      pinboard.add(article) rescue false
    rescue
    end

    bar.increment!
  end
  clear_list = %x{cp -R ~/dev/pinboard_tools/lib/Bookmarks.plist ~/Library/Safari/Bookmarks.plist}
end