Created
November 18, 2017 13:32
-
-
Save mrbidon/1629fd1b5781b041b684c3a493f8b645 to your computer and use it in GitHub Desktop.
Convert a Firefox jsonlz4 bookmark file to a Mozilla HTML bookmark format
This file contains 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
# -*- 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'])) |
Doesn't work on windows7
File "open.py", line 26, in <module>
parsed = json.loads(f.read())
File "C:\python\\lib\encodings\cp1250.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 247: character maps to <undefined>
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.
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
Are you sure you can read the binary file (.jsonlz4) with this script as you state in the comment?