-
Notifications
You must be signed in to change notification settings - Fork 73
/
firefox_recovery_to_html.py
executable file
·68 lines (52 loc) · 1.9 KB
/
firefox_recovery_to_html.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
"""
Script to convert Firefox profile sessionstore-backups/recovery.js to HTML links
Sometime in the late-20-something to early-30-something releases, Firefox stopped
writing its venerable sessionstore.js file inside profile directories, in favor
of a recovery.js file inside the sessionstore-backups/ directory. This script
parses that file and outputs HTML with a list of links for your open tabs.
Useful when sync is mishebaving.
Copyright 2014 Jason Antman <[email protected]> <http://www.jasonantman.com>
Free for any use provided that patches are submitted back to me.
The latest version of this script can be found at:
https://github.com/jantman/misc-scripts/blob/master/firefox_recovery_to_html.py
CHANGELOG:
2014-12-08 jantman:
- initial script
"""
import os
import sys
import json
try:
from html import escape # py3
except ImportError:
from cgi import escape # py2
def usage():
print("USAGE: firefox_recovery_to_html.py /path/to/profile_dir/sessionstore-backups/recovery.js")
if len(sys.argv) < 1:
usage()
raise SystemExit(1)
fpath = sys.argv[1]
if fpath == '--help' or fpath == '-h':
usage()
raise SystemExit()
if not os.path.exists(fpath):
raise SystemExit("ERROR: file does not exist: %s" % fpath)
with open(fpath, 'r') as fh:
raw = fh.read()
js = json.loads(raw)
"""
_closedWindows
windows
session
selectedWindow
global
"""
print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
print('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>recovery.js tabs</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />')
print('</head><body><ol>')
for i in js['windows']:
for x in i['tabs']:
tab = x['entries'][-1]
print('<li><a href="{url}">{title}</a></li>'.format(title=tab['title'], url=escape(tab['url'])))
print('</ol></body></html>')