Class: PinboardTools::SafariReadingListImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/pinboard_tools/srl_to_pinboard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ SafariReadingListImporter



21
22
23
# File 'lib/pinboard_tools/srl_to_pinboard.rb', line 21

def initialize(args)
  @tagger = Tagger.new(tag: nil, verbose: args[:verbose])
end

Instance Attribute Details

#taggerObject

Returns the value of attribute tagger.



19
20
21
# File 'lib/pinboard_tools/srl_to_pinboard.rb', line 19

def tagger
  @tagger
end

Instance Method Details

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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.(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