Created
May 13, 2012 20:47
-
-
Save warner/2690106 to your computer and use it in GitHub Desktop.
turn a firefox sessionstore.js into an HTML page
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/python | |
import os, sys, json, time | |
from twisted.python import usage | |
class Usage(usage.Options): | |
optParameters = [ | |
("sessionfile", "s", None, "sessionstore.js to read, uses new-b9 profile by default"), | |
("outfile", "o", "-", "write tabs.html to here"), | |
] | |
def postOptions(self): | |
if self["sessionfile"] is None: | |
self["sessionfile"] = os.path.expanduser("~/Library/Application Support/Firefox/Profiles/sjkwtbb1.new-b9/sessionstore.js") | |
self.sessionfile = open(self["sessionfile"], "rb") | |
if self["outfile"] == "-": | |
self.outfile = sys.stdout | |
else: | |
self.outfile = open(self["outfile"], "wb") | |
o = Usage() | |
o.parseOptions() | |
ss = json.loads(o.sessionfile.read().decode("utf-8")) | |
o.outfile.write(""" | |
<html> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | |
<title>Open Tabs from session file</title> | |
</head> | |
<body> | |
<h1>Open Tabs from Session File</h1> | |
<p>File mtime %s, Recorded session.lastUpdate %s</p> | |
<ul> | |
""" % (time.ctime(os.stat(o["sessionfile"]).st_mtime), | |
time.ctime(ss["session"]["lastUpdate"]/1000.0)) | |
) | |
urls = [] | |
for w in ss["windows"]: | |
for t in w["tabs"]: | |
e = t["entries"][t["index"]-1] | |
url = e["url"] | |
title = e["title"] | |
line = ' <li><a href="%s">%s</a> : <tt>%s</tt></li>\n' % \ | |
(e["url"], e["title"], e["url"]) | |
o.outfile.write(line.encode("utf-8")) | |
#print e["title"] | |
#print e["url"] | |
o.outfile.write(""" | |
</ul> | |
<p></p> | |
</body> | |
</html> | |
""" | |
) | |
o.outfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment