Skip to content

Instantly share code, notes, and snippets.

@yunesj
Created May 15, 2018 21:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yunesj/ce31815f3fff2784d2e239431a5bea77 to your computer and use it in GitHub Desktop.
Convert SessionManager sessions directory to HTML that can be imported into Firefox Quantum
#!/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>""")
@yunesj
Copy link
Author

yunesj commented May 15, 2018

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".

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