Last active
May 21, 2016 14:31
-
-
Save tsumare/9787c049cbd2cf30a603 to your computer and use it in GitHub Desktop.
Parse firefox session store into a HTML page with links to tabs.
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 python | |
import json, sys | |
from pprint import pprint | |
def escape(html): | |
return html.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"') | |
sessionstore = json.load(open(sys.argv[1],'r')) | |
sessionstore_windowtabs = map(lambda x: x['tabs'], sessionstore['windows']) | |
outf = open(sys.argv[2], 'w') | |
print >>outf, '<html><head><title>Session Restore Tabs</title></head><body>' | |
windows = 1 | |
for window in sessionstore_windowtabs: | |
print >>outf, '<h1>Window {}</h1><p><ul>'.format(windows) | |
windows += 1 | |
for tab in window: | |
#tab['entries'][:] = [tab['entries'][-1]] | |
entry = tab['entries'][int(tab.get('index',0))-1] # index is 1-based 'active' index in entries (0-1 = -1 = 'last') | |
title = escape(entry.get('title','Untitled')) | |
url = escape(entry.get('url','about:blank')) | |
print >>outf, u'<li><a href="{url}">{title}</a></li>'.format(title=title, url=url).encode('ascii','xmlcharrefreplace') | |
print >>outf, '</ul></p>' | |
print >>outf, '</body></html>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment