code/firefox_session_textareas.py
author Uche Ogbuji <uche@ogbuji.net>
Mon Apr 13 23:03:12 2009 -0600 (2009-04-13)
changeset 5 9a2f82c0db75
parent 1 8d7e294e0b51
permissions -rw-r--r--
Add transform to view Akara services as Atom
     1 '''
     2 firefox_session_textareas.py - Recover text area content from Firefox session files
     3 
     4 Print out text area content cached by Firefox in the saved session file.
     5 
     6 Sample usage:
     7 
     8 python firefox_session_textareas.py "~/.firefox/Profiles/*/sessionstore.js"
     9     -- Print out all text area content found (including the corresponding page URL)
    10 
    11 python firefox_session_textareas.py "~/.firefox/Profiles/*/sessionstore.js" spam
    12     -- Print out all only text areas found to contain the string "spam"
    13        (or whose corresponding page URL contains that string)
    14 '''
    15 
    16 import urllib
    17 import sys
    18 import re
    19 
    20 TEXTAREA_PAT = re.compile('{url:"([^"]*)"[^}]*}[^}]*text:"#editor-textarea=([^"]*)"')
    21 HEADING_TPL = '------------ firefox_session_textareas.py - %s ------------'
    22 
    23 def textarea_content(s):
    24     return urllib.unquote(s)
    25 
    26 #FIXME: Use optparse, etc to clean up command line handling
    27 sessioninfo = open(sys.argv[1]).read()
    28 try:
    29     search = sys.argv[2]
    30 except IndexError:
    31     search = None
    32 
    33 
    34 for match in TEXTAREA_PAT.finditer(sessioninfo):
    35     if search is None or search in match.group(0):
    36         print HEADING_TPL%match.group(1)
    37         print
    38         print textarea_content(match.group(2))
    39         print
    40 
    41 #
    42