-
Notifications
You must be signed in to change notification settings - Fork 21
/
firefox-closed-tabs.py
102 lines (87 loc) · 2.47 KB
/
firefox-closed-tabs.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# firefox-closed-tabs.py - Show closed tabs in Firefox profile - 18/dic/2012
# Copyright (C) 2012 Pablo Castellano <pablo@anche.no>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__ = "Pablo Castellano <pablo@anche.no>"
__version__ = 0.1
__license__ = "GNU GPLv3+"
__date__ = "18/12/2012"
import json
import sys
import os
DEFAULT_DIR = '%s/.mozilla/firefox/' %os.path.expanduser('~')
ow = os.walk(DEFAULT_DIR)
folders = ow.next()[1]
folders.remove('Crash Reports')
print 'firefox-closed-tabs.py - Show closed tabs in Firefox profile'
print 'Usage: %s [sessionstore.js file]' %sys.argv[0]
print
if len(sys.argv) == 2:
FILENAME=sys.argv[1]
else:
if len(folders) > 1:
print 'I have found %d firefox profiles:' %len(folders)
for i, folder in enumerate(folders):
print ' %d: %s' %(i, folder.split('.')[1])
opt = int(raw_input('Please choose a number: '))
while (opt < 0 or opt > len(folders)-1):
opt = int(raw_input('Invalid number. Please try again: '))
FILENAME = os.path.join(DEFAULT_DIR, folders[opt], 'sessionstore.js')
else:
FILENAME = os.path.join(DEFAULT_DIR, folders[0], 'sessionstore.js')
print 'Using filename:', FILENAME
fp = open(FILENAME)
j = json.load(fp)
fp.close()
windows = j.get('_closedWindows')
#len(windows) == 3
c = windows[0]
# len(c) == 12
#for l in c:
# print l
"""
cookies
_shouldRestore
title
tabs
selected
_closedTabs
extData
height
width
sizemode
screenY
screenX
c['tabs']
c['_closedTabs']
c['tabs'][0]['entries']
c['tabs'][0]['entries'][0]['title']
c['tabs'][0]['entries'][0]['url']
"""
print 'TABS:', len(c['tabs'])
num_e = 0
num_t = 0
for t in c['tabs']:
num_t += 1
print 'Tab num', num_t
if len(t['entries']) > 1:
# What happens here??
pass
for e in t['entries']:
num_e += 1
print e['url']
print 'ENTRIES:', num_e