Skip to content

Instantly share code, notes, and snippets.

@ldotlopez
Last active August 21, 2025 15:08
Show Gist options
  • Select an option

  • Save ldotlopez/4bc369124dc9f4e65366145157522d9d to your computer and use it in GitHub Desktop.

Select an option

Save ldotlopez/4bc369124dc9f4e65366145157522d9d to your computer and use it in GitHub Desktop.
Convert data from pocket export to firefox bookmarks importable file.
#!/usr/bin/env python3
import csv
from typing import Iterable
TMPL = """
<DL>
<DT><H3>Pocket</H3>
<DL>
{items}
</DL>
</DL>
"""
ITEM_TMPL = """
<DT><A HREF="{url}" ADD_DATE="{add_date}" LAST_MODIFIED="{last_modified}"
TAGS="{tags}">{title}</A>
"""
def format_container(items: Iterable[dict]) -> str:
return TMPL.format(items="\n".join(items))
def format_bookmark(row: dict) -> str:
tags = row.get("tags", "").replace("|", ",")
return ITEM_TMPL.format(
url=row["url"],
add_date=row["time_added"],
last_modified=row["time_added"],
tags=tags,
title=row["title"],
)
def main():
import sys
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} bookmarks.html")
with open(sys.argv[1]) as fh:
fieldnames = fh.readline().strip().split(",")
reader = csv.DictReader(
fh,
fieldnames=fieldnames,
)
print(format_container((format_bookmark(x) for x in reader)))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment