-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinboard-list-export.rb
executable file
·98 lines (76 loc) · 2.33 KB
/
pinboard-list-export.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env ruby
#
# pinboard-list-export.rb
#
#
# Created by Henning Schumann
# Copyright 2011 Henning Schumann. MIT-License (see README).
#
# Homepage: http://github.com/hng/pinboard-list-export
# Usage: See pinboard-list-export.rb --help
require 'optparse'
require 'pinboard'
@options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: pinboard-list-export.rb [options]"
@options[:tags] = false
opts.on('-t', '--tags TAGS', 'pinboard tags to export into list (separated by comma)') do |tags|
@options[:tags] = tags
end
@options[:user] = false
opts.on('-u', '--user USER', 'pinboard username') do |user|
@options[:user] = user
end
@options[:password] = false
opts.on('-p', '--password PASSWORD', 'pinboard password') do |pwd|
@options[:password] = pwd
end
@options[:format] = false
opts.on('-f', '--format FORMAT', 'output format: html (default), markdown, textile, wiki, text') do |f|
@options[:format] = f
end
opts.on('-h', '--help', 'Displays this screen') do
puts opts
exit
end
end
optparse.parse!
@output = ""
if(!@options[:format] || @options[:format] == "html")
@output << "<ul>\n"
end
if(!@options[:user])
print "User: "
@options[:user] = gets.chomp
end
if(!@options[:password])
print "Password: "
@options[:password] = gets.chomp
end
if(@options[:tags])
pinboard = Pinboard::Client.new(:username => @options[:user], :password => @options[:password])
posts = pinboard.posts(:tag => @options[:tags])
if !posts.nil?
posts.each do |p|
if(!@options[:format] || @options[:format] == "html")
@output << "<li><a href='#{p.href}'>#{p.description}</a></li>\n"
elsif(@options[:format] == "markdown")
@output << "* [#{p.description}](#{p.href})\n"
elsif(@options[:format] == "textile")
@output << "* \"#{p.description}\":#{p.href}\n"
elsif(@options[:format] == "wiki")
@output << "* [#{p.href} #{p.description}]\n"
elsif(@options[:format] == "text")
@output << "\t-\t#{p.description}: <#{p.href}>\n"
@output << "\t\t#{p.extended}\n" unless p.extended.empty?
@output << "\n"
end
end
if(!@options[:format] || @options[:format] == "html")
@output << "</ul>"
end
puts @output
else
puts "No bookmarks found."
end
end