Created
January 12, 2022 02:56
-
-
Save schwa/a2283cbbf80bccabd05bf89b85e28ed9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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