Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Grab all Pinboard.in bookmarks for your account, create a bookmark file for Launchbar indexing
#!/usr/bin/ruby
=begin
This script is designed to generate a simple html file with _all_ of your Pinboard.in bookmarks
The HTML file can be added to Launchbar's index as a custom bookmark file and you can search
your entire Pinboard.in collection instantly from Launchbar (by title only). It includes
any applied tags as part of the title to aid in searching.
This does no checking for deltas, it just grabs the whole bunch and overwrites the html file
every time. Don't run it too frequently.
Set your username, password and the path/filename to write to below.
=end
### User configuration
PB_USERNAME = 'username'
PB_PASSWORD = 'password'
BOOKMARK_FILE = 'path/to/store/PinboardBookmarks.html'
### END config
require 'cgi'
require 'fileutils'
require 'net/https'
require 'rexml/document'
class Net::HTTP
alias_method :old_initialize, :initialize
def initialize(*args)
old_initialize(*args)
@ssl_context = OpenSSL::SSL::SSLContext.new
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
end
def get_bookmarks
xml = ''
http = Net::HTTP.new('api.pinboard.in', 443)
http.use_ssl = true
http.start do |http|
request = Net::HTTP::Get.new('/v1/posts/all')
request.basic_auth PB_USERNAME,PB_PASSWORD
response = http.request(request)
response.value
xml = response.body
end
return REXML::Document.new(xml)
end
def bookmarks_to_array(doc)
bookmarks = []
doc.elements.each('posts/post') do |ele|
post = {}
ele.attributes.each {|key,val|
post[key] = val;
}
bookmarks.push(post)
end
return bookmarks
end
bookmarks = bookmarks_to_array(get_bookmarks)
output = ""
bookmarks.each do |b|
output += %Q{<a href="#{b['href']}" title="#{CGI.escapeHTML(b['extended']).gsub(/\n/,' ')}">#{b['description'].gsub(/\n+/,"\n")} @#{b['tag'].split(' ').join(' @')}</a>\n}
end
# Append to a file:
open(File.expand_path(BOOKMARK_FILE), 'w') { |f|
f.puts output
}
@dlo
Copy link

dlo commented Jan 24, 2013

If you'd like to use the OS X keychain to prompt for your password (and having writing your password in plain text in here), replace line 15 with something like this:

PB_PASSWORD = `security find-internet-password -s pinboard.in -w | tr -d '\n'`

@dlo
Copy link

dlo commented Jan 24, 2013

Forked and wrote a Python version that pulls all bookmarks on the first sync, and does incremental updates afterwards. Also uses the Mac OS X keychain to retrieve your password so it doesn't need to live in a file on your computer in plain text.

https://gist.github.com/4629073

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment