Skip to content

Instantly share code, notes, and snippets.

@mrbidon
Created November 18, 2017 13:32
Show Gist options
  • Save mrbidon/1629fd1b5781b041b684c3a493f8b645 to your computer and use it in GitHub Desktop.
Save mrbidon/1629fd1b5781b041b684c3a493f8b645 to your computer and use it in GitHub Desktop.
Convert a Firefox jsonlz4 bookmark file to a Mozilla HTML bookmark format
# -*- coding: utf-8 -*-
# this little script convert a Firefox jsonlz4 bookmark file to a Mozilla HTML bookmark format
import json
import sys
def parse(dic, title):
result = ""
result += '<DT><H3 FOLDED ADD_DATE="">{title}</H3>'.format(title=title)
result += '<DL>'
for url in dic:
if "uri" in url:
result += '<A HREF="{uri}" ADD_DATE="{date}" PRIVATE="0" TAGS="svg,reference">{title}</A>'.format(uri=url['uri'], date=url['lastModified'], title=url['title'])
elif 'children' in url :
result += parse(url['children'], url['title'])
result += '</DL>'
return result
with open(sys.argv[1]) as f :
print("""<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!--This is an automatically generated file.
It will be read and overwritten.
Do Not Edit! -->
<Title>Bookmarks</Title>
<H1>Bookmarks</H1>""")
parsed = json.loads(f.read())
if('children' in parsed):
print(parse(parsed['children'], parsed['title']))
@BasicAcid
Copy link

BasicAcid commented Feb 9, 2020

Yes, the description is not complete, I understood what the author was trying to do by going to this blog page

In fact he used this script to convert the binary file beforehand.

@mrbidon
Copy link
Author

mrbidon commented Feb 9, 2020

I haven't see these comment....

It's a one shot script I've done and find that might be helpful (And in fact, it is :))

As @BasicAcid said, you have to use dejsonlz4 first to make it works

git clone https://github.com/avih/dejsonlz4
cd dejsonlz4
gcc -Wall -o dejsonlz4 src/dejsonlz4.c src/lz4.c

./dejsonlz4 [nom_du_fichier_jsonlz4]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment