browser/firefox: refactor ff{bookmarks,history}

This commit is contained in:
Henrik Lissner 2017-04-09 23:36:06 -04:00
parent 0021426686
commit 36abb82f63
3 changed files with 11 additions and 7 deletions

View file

@ -4,10 +4,9 @@ from pyfzf import FzfPrompt
from lib.FirefoxProfile import FirefoxProfile from lib.FirefoxProfile import FirefoxProfile
if __name__ == '__main__': with FirefoxProfile.default() as ff:
ff = FirefoxProfile.default()
choice = FzfPrompt().prompt(ff.bookmarks()) choice = FzfPrompt().prompt(ff.bookmarks())
if choice: if choice:
ff.open("http" + choice[0].split(", http")[1]) ff.browse("http" + choice[0].split(", http")[1])
else: else:
print("Aborted") print("Aborted")

View file

@ -4,10 +4,9 @@ from pyfzf import FzfPrompt
from lib.FirefoxProfile import FirefoxProfile from lib.FirefoxProfile import FirefoxProfile
if __name__ == '__main__': with FirefoxProfile.default() as ff:
ff = FirefoxProfile.default()
choice = FzfPrompt().prompt(ff.history()) choice = FzfPrompt().prompt(ff.history())
if choice: if choice:
ff.open("http" + choice[0].split(", http")[1]) ff.browse("http" + choice[0].split(", http")[1])
else: else:
print("Aborted") print("Aborted")

View file

@ -13,6 +13,12 @@ class FirefoxProfile:
self.db = sqlite.connect(dbfile) self.db = sqlite.connect(dbfile)
self.cur = self.db.cursor() self.cur = self.db.cursor()
def __enter__(self):
return FirefoxProfile.default()
def __exit__(self, _, __, ___):
self.close()
@staticmethod @staticmethod
def default(): def default():
dbfile = None dbfile = None
@ -59,7 +65,7 @@ class FirefoxProfile:
result.append(key) result.append(key)
return result return result
def open(self, url): def browse(self, url):
if _platform.startswith("linux"): if _platform.startswith("linux"):
os.system('xdg-open "{}"'.format(url)) os.system('xdg-open "{}"'.format(url))
elif _platform == "darwin": elif _platform == "darwin":