Created
May 31, 2025 21:56
-
-
Save Romern/d56f3fe13a48f70e1879595fd10fe10c to your computer and use it in GitHub Desktop.
Loads a Firefox Bookmark export file and writes the titles and urls in a folder structure
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 json | |
import string | |
from pathlib import Path | |
import sys | |
if len(sys.argv) != 3: | |
print(f'Usage: {sys.argv[0]} bookmarkfile.json outputPathBase') | |
exit() | |
data = json.load(open(sys.argv[1],'r')) | |
outputdir = Path(sys.argv[2]) | |
whitelist = string.ascii_letters + string.digits + '_-,. ' | |
def to_safe(s): | |
return ''.join(i for i in s if i in whitelist) | |
def process_folder(node, path: Path): | |
ending = '.md' if not node.get('children') else '' | |
out = path / (to_safe(node['title']) + ending) | |
if not node.get('children'): | |
if node.get('uri'): | |
out.write_text(f"# {node['title']}\n{node['uri']}") | |
else: | |
out.mkdir(exist_ok=True) | |
for i in node['children']: | |
process_folder(i, out) | |
process_folder(data, outputdir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment