Skip to content

Instantly share code, notes, and snippets.

@schwa
Created January 12, 2022 02:56
Show Gist options
  • Select an option

  • Save schwa/a2283cbbf80bccabd05bf89b85e28ed9 to your computer and use it in GitHub Desktop.

Select an option

Save schwa/a2283cbbf80bccabd05bf89b85e28ed9 to your computer and use it in GitHub Desktop.
import subprocess
from pathlib import Path
import plistlib
import pinboard # install via pip
from shutil import which
PINBOARD_TOKEN = "< your pinboard token>"
subprocess.check_call(
[
which("plutil"),
"-convert",
"xml1",
"-o",
"/tmp/Bookmarks.plist",
Path("~/Library/Safari/Bookmarks.plist").expanduser(),
]
)
bookmarks = plistlib.load(open("/tmp/Bookmarks.plist", "rb"))
groups = [
group
for group in bookmarks["Children"]
if group["Title"] == "com.apple.ReadingList"
]
reading_list = groups[0]
reading_list_items = reading_list.get("Children", [])
bookmarks = [
(item["URLString"], item["URIDictionary"]["title"]) for item in reading_list_items
]
pb = pinboard.Pinboard(PINBOARD_TOKEN)
for url, title in bookmarks:
print(url)
result = pb.posts.add(
url=url,
description=title if title else "Untitled",
tags="SafariReadingList",
shared=False,
toread=True,
)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment