Skip to content

Instantly share code, notes, and snippets.

@Romern
Created May 31, 2025 21:56
Show Gist options
  • Save Romern/d56f3fe13a48f70e1879595fd10fe10c to your computer and use it in GitHub Desktop.
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
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