Skip to content

Instantly share code, notes, and snippets.



Forked from dlo/
Last active Sep 5, 2019
What would you like to do?
Python version of that pulls all bookmarks on the first sync, and does incremental updates afterwards. Updated to use Pinboard API token instead of password authentication.
#!/usr/bin/env python
This script is designed to generate a simple html file with _all_ of your bookmarks The HTML file can be added to Launchbar's index as a
custom bookmark file and you can search your entire collection
instantly from Launchbar (by title only). It includes any applied tags as part
of the title to aid in searching.
You should edit the `token`, `bookmark_filename`, and `local_timezone`
variables to suit your preferences.
* pytz
* requests
* dateutil
from datetime import datetime
import subprocess
import os
import cgi
import pytz
import requests
from dateutil import parser as date_parser
# Settings
# Your Pinboard API token from
# For example YOURUSERNAME:1234567890ABCDEF1234
token = ""
# The path where you'd like to store your HTML export
bookmark_filename = os.environ['HOME'] + "/Cloud/PinboardBookmarks.html"
# Your timezone
local_timezone = "America/Los_Angeles"
# (optional) A tag that you want to export by
tag = None
url = None
bookmark_format = u"""<a href="{href}" title="{extended}">{description}</a>\n"""
auth_query = {'auth_token': token}
def quote(text):
return cgi.escape(text, quote=True).replace("\n", " ")
timestamp = os.stat(bookmark_filename).st_mtime
except OSError:
if tag:
url = "{}".format(tag)
url = ""
last_modified_local_time = datetime.fromtimestamp(timestamp, \
last_modified = last_modified_local_time.astimezone(pytz.timezone("UTC"))
# Check if bookmarks have been updated remotely since last local update
response = requests.get("",
last_modified_on_server = date_parser.parse(response.json()['update_time'])
if last_modified_on_server > last_modified:
if tag:
url = "{}&tag={}" \
.format(last_modified.strftime("%FT%TZ"), tag)
url = "{}" \
if url is not None:
response = requests.get(url, params=auth_query)
with open(bookmark_filename, 'a+') as bookmark_file:
for bookmark in response.json():
bookmark['description'] = quote(bookmark['description'])
bookmark['extended'] = quote(bookmark['extended'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.