X-Git-Url: https://git.svenne.dk/?p=public%2Fmisc-sysadmin.git;a=blobdiff_plain;f=save_firefox_urls.py;h=57cf0cf6156bc1579ecaf55652262a8f332b22d4;hp=82dcd1c9179795fc65e4e132c2aa5e50921da2e7;hb=refs%2Fheads%2Fmaster;hpb=3d2493ddf3f5692893741eddf409457740911dae diff --git a/save_firefox_urls.py b/save_firefox_urls.py index 82dcd1c..57cf0cf 100755 --- a/save_firefox_urls.py +++ b/save_firefox_urls.py @@ -17,7 +17,10 @@ import time ts = time.strftime("%Y-%m-%d-%H:%M:%S") -profile = "default" +if len(sys.argv) == 2: + profile = sys.argv[1] +else: + profile = "default" basedir = os.environ['HOME'] + "/.mozilla/firefox/" histdir = os.environ['HOME'] + "/mozhistory"; if not os.path.exists(histdir): @@ -37,22 +40,37 @@ if thefile == None: print("cant find profile") sys.exit() -data = open(thefile + "/sessionstore.js",'r').read() +thefile = basedir + "/" + thefile + "/sessionstore.js" +print ("Using " + thefile) +data = open(thefile,'r').read() j = json.loads(data) fields = ["title","url"] -tabs = len(j['windows'][0]["tabs"]) +windows = len(j['windows']) outfp = open(outfile,"w") -for t in range(tabs): - try: - title = j['windows'][0]["tabs"][t]["entries"][0]["title"] - except: - title = ""; - try: - url = j['windows'][0]["tabs"][t]["entries"][0]["url"] - except: - continue - outfp.write( str(t) + " " + title + " " + url + "\n") +for w in range(windows): + print("Looking at window " + str(w)) + tabs = len(j['windows'][w]["tabs"]) + print (" Found " + str(tabs) + " tabs") + for t in range(tabs): + print(" Looking at tab " + str(w)) + entries = len(j['windows'][w]["tabs"][t]["entries"]) + print(" History depth: " + str(entries)) + + for e in range(entries): + try: + title = j['windows'][w]["tabs"][t]["entries"][e]["title"] + except: + title = ""; + try: + url = j['windows'][w]["tabs"][t]["entries"][e]["url"] + except: + continue + print (" Found:") + print (" Entry: " + str(e)) + print (" Url : " + url) + print (" Title: " + title) + outfp.write( str(w) + " " + str(t) + " " + str(e) + " " + url + " \"" + title + "\"\n") outfp.close() print ("Saved as " + outfile)