From 25ecac21fab2fc3d89e557b08f90183093a8ede1 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Sun, 3 Jan 2021 09:00:40 +0200 Subject: [PATCH] List the firefox places.sqlite --- buuka.cabal | 4 +++ default.nix | 16 ++++++----- src/Operations/Import/Firefox.hs | 47 ++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 src/Operations/Import/Firefox.hs diff --git a/buuka.cabal b/buuka.cabal index 8b64432..c4d48b2 100644 --- a/buuka.cabal +++ b/buuka.cabal @@ -40,6 +40,7 @@ library , Operations.Insert , Operations.List , Operations.Query + , Operations.Import.Firefox , Operations , Data.Environment , Data.Buuka @@ -61,6 +62,9 @@ library , lens , hashable , regex-tdfa + , sqlite-simple + , conduit + , conduit-extra hs-source-dirs: src executable buuka diff --git a/default.nix b/default.nix index 795a5dd..ece3a3d 100644 --- a/default.nix +++ b/default.nix @@ -1,8 +1,9 @@ -{ mkDerivation, aeson, base, bytestring, containers -, deriving-compat, exceptions, filepath, hashable, hashids -, hedgehog, hedgehog-corpus, lens, mtl, optparse-applicative -, regex-tdfa, stdenv, tasty, tasty-hedgehog, tasty-hunit, text -, transformers, unliftio, vector, yaml +{ mkDerivation, aeson, base, bytestring, conduit, conduit-extra +, containers, deriving-compat, exceptions, filepath, hashable +, hashids, hedgehog, hedgehog-corpus, lens, mtl +, optparse-applicative, regex-tdfa, sqlite-simple, stdenv, tasty +, tasty-hedgehog, tasty-hunit, text, transformers, unliftio, vector +, yaml }: mkDerivation { pname = "buuka"; @@ -11,8 +12,9 @@ mkDerivation { isLibrary = true; isExecutable = true; libraryHaskellDepends = [ - aeson base bytestring containers exceptions filepath hashable - hashids lens mtl regex-tdfa text transformers unliftio vector yaml + aeson base bytestring conduit conduit-extra containers exceptions + filepath hashable hashids lens mtl regex-tdfa sqlite-simple text + transformers unliftio vector yaml ]; executableHaskellDepends = [ base optparse-applicative unliftio ]; testHaskellDepends = [ diff --git a/src/Operations/Import/Firefox.hs b/src/Operations/Import/Firefox.hs new file mode 100644 index 0000000..9671aa7 --- /dev/null +++ b/src/Operations/Import/Firefox.hs @@ -0,0 +1,47 @@ +{-| +Module : Operations.Import.Firefox +Description : Imports from firefox +Copyright : (c) Mats Rauhala, 2020 +License : BSD-3-Clause +Maintainer : mats.rauhala@iki.fi +Stability : experimental +Portability : POSIX + +Imports from firefox. Firefox needs to be closed when doing the import +-} +module Operations.Import.Firefox where + +import Conduit +import qualified Data.Conduit.Combinators as C + +import System.FilePath + (takeFileName, ()) + +import Control.Exception + (Exception) + +import System.Environment + (lookupEnv) + +import GHC.Stack + +-- select p.title, p.url from moz_bookmarks b join moz_places p on b.fk = p.id +-- +-- select keyword from moz_keywords where place_id = ? + +newtype ImportException + = HomeNotFound CallStack + deriving stock (Show) + deriving anyclass (Exception) + +stores + :: MonadResource m + => MonadThrow m + => MonadIO m + => HasCallStack + => ConduitT i FilePath m () +stores = liftIO (lookupEnv "HOME") >>= maybe (throwM (HomeNotFound callStack)) listStores + where + listStores home = + sourceDirectoryDeep False (home ".mozilla/firefox") + .| C.filter (\p -> takeFileName p == "places.sqlite")