Created
July 6, 2009 15:34
-
-
Save JoeGermuska/141490 to your computer and use it in GitHub Desktop.
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 | |
import os, os.path | |
DEFAULT_PROFILE_NAME = "default.2m2" | |
SESSION_PATH = "Library/Application Support/Firefox/Profiles/%s/sessionstore.js" | |
# TODO consider generalizing the session store to open (different users, different profiles) | |
def session_path(): | |
return os.path.join(os.environ['HOME'],SESSION_PATH % DEFAULT_PROFILE_NAME) | |
def load_session(): | |
f = open(session_path()) | |
s = f.read() | |
s = s[1:-1] # strip parentheses to make pure python json object | |
return json.loads(s) | |
def decompose_session(): | |
windows = [] | |
for window in load_session()['windows']: | |
tabs = [] | |
windows.append(tabs) | |
for tab in window['tabs']: | |
if len(tab['entries']) != 0: | |
tabs.append({ 'url': tab['entries'][-1]['url'], | |
'title': tab['entries'][-1]['title'], | |
}) | |
return windows | |
def dump_session(): | |
for w,window in enumerate(decompose_session()): | |
for t,tab in enumerate(window): | |
print "%3i %3i %s" % (w,t,tab['title'].encode("utf-8")) | |
print " %s" % tab['url'].encode("utf-8") | |
def tab_count(): | |
return sum(map(len,[w for w in decompose_session()])) | |
if __name__ == "__main__": | |
dump_session() | |
print "%i total tabs" % tab_count() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment