Created
May 15, 2018 21:03
Star
You must be signed in to star a gist
Convert SessionManager sessions directory to HTML that can be imported into Firefox Quantum
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
#!/usr/bin/env python3 | |
import os | |
import glob | |
import json | |
sesh_dir = '/Users/jeff/Desktop/sessions/' | |
print (r"""<!DOCTYPE NETSCAPE-Bookmark-file-1> | |
<Title>Bookmarks</Title> | |
<H1>Bookmarks</H1> | |
""") | |
for path in glob.glob(sesh_dir + '*.session'): | |
print (r""" <DT><H3 FOLDED>%s</H3> | |
<DL><p>""" % os.path.basename(path)) | |
with open(path, 'U') as sesh_file: | |
sesh_json = None | |
for line in sesh_file: | |
line = line.strip() | |
if line.startswith('{"windows":') or line.startswith('{"version":'): | |
sesh_json = json.loads(line) | |
break | |
assert sesh_json is not None | |
for w, window in enumerate(sesh_json['windows']): | |
print (r""" <DT><H3 FOLDED>Window %d</H3> | |
<DL><p> | |
""" % w) | |
tabs = window['tabs'] | |
for t, tab in enumerate(tabs): | |
entries = tab['entries'] | |
# it seems like the entries are the history. take the most recent one | |
# for e, entry in enumerate(entries): | |
e, entry = list(enumerate(entries))[-1] | |
# print (w, t, e, entry.get('title'), entry['url'], tab.get('lastAccessed')) | |
print (r""" <DT><A HREF="%s" ADD_DATE="%d">%s</A>""" % (entry['url'], tab.get('lastAccessed', 0), entry.get('title'))) | |
print (r""" </DL><p>""") | |
print (r""" </DL><p>""") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change the directory (sessions are stored within a profile/sessions), run the script and add "> bookmarks.html" so that the output is written to a file. Import in Firefox Quantum in "Show All Bookmarks".