Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Granitosaurus/61c4da2e391a610c2646a42238068a6f to your computer and use it in GitHub Desktop.
Save Granitosaurus/61c4da2e391a610c2646a42238068a6f to your computer and use it in GitHub Desktop.
export qutebrowser bookmarks to firefox compatible bookmarks HTML file.
"""convert qutebrowser bookmarks to firefox bookmark HTML file for importing to firefox"""
from pathlib import Path
from os import getenv
xdg_config = Path(getenv('XDG_CONFIG_HOME', Path.home() / '.config'))
bookmarks = (xdg_config / 'qutebrowser/bookmarks/urls').read_text().splitlines()
html = [
'<!DOCTYPE NETSCAPE-Bookmark-file-1>',
'<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">',
'<TITLE>Bookmarks</TITLE>',
'<H1>Bookmarks</H1>',
'<DL>'
]
for url in bookmarks:
url, text = url.split(' ', 1)
html.append(f'<DT><A HREF="{url}">{text}</A></DT>')
html.append('</DL>')
Path('bookmarks.html').write_text('\n'.join(html))
print('Bookmarks have been successfully converted to HTML format to bookmarks.html file.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment