clit-0.2.0.0: src/Web/Tweet/Utils.hs
-- | Miscellaneous functions that don't fit the project directly
module Web.Tweet.Utils where
import qualified Data.ByteString.Char8 as BS
-- | helper function to get the key as read from a file
keyLinePie :: String -> String
keyLinePie = takeWhile (/=':')
-- | Pick out a key value from a key
lineByKey :: BS.ByteString -> [(BS.ByteString, BS.ByteString)] -> BS.ByteString
lineByKey key = snd . head . (filter (\i -> fst i == key))
-- | Filter a line of a file for only the actual data and no descriptors
filterLine :: String -> String
filterLine = reverse . (takeWhile (not . (`elem` (" :" :: String)))) . reverse
-- | Get pairs of "key" to search for and actual values
getConfigData :: FilePath -> IO [(BS.ByteString, BS.ByteString)]
getConfigData filepath = zip <$> keys <*> content
where content = (map (BS.pack . filterLine)) . lines <$> file
keys = (map (BS.pack . keyLinePie)) . lines <$> file
file = readFile filepath