packages feed

clit 0.2.0.2 → 0.2.2.2

raw patch · 3 files changed

+29/−16 lines, 3 filesdep +textdep ~basedep ~clit

Dependencies added: text

Dependency ranges changed: base, clit

Files

clit.cabal view
@@ -1,5 +1,5 @@ name: clit-version: 0.2.0.2+version: 0.2.2.2 cabal-version: >=1.10 build-type: Simple license: BSD3@@ -33,7 +33,8 @@         split >=0.2.3.1 && <0.3,         optparse-applicative >=0.12.1.0 && <0.13.0.0,         lens ==4.14.*,-        data-default >=0.7.1.1 && <0.8+        data-default >=0.7.1.1 && <0.8,+        text >=1.2.2.1 && <1.3     default-language: Haskell2010     hs-source-dirs: src     other-modules:@@ -44,8 +45,8 @@ executable tweet     main-is: Main.hs     build-depends:-        base >=4.9.0.0 && <4.10,-        clit >=0.2.0.2 && <0.3+        base >=4.9.1.0 && <4.10,+        clit >=0.2.2.2 && <0.3     default-language: Haskell2010     hs-source-dirs: app     ghc-options: -threaded -rtsopts -with-rtsopts=-N
src/Web/Tweet.hs view
@@ -35,6 +35,8 @@ import Network.HTTP.Types.Status (statusCode) import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy.Char8 as BSL+import qualified Data.Text as T+import Data.Text.Encoding import Data.Char (toLower) import Web.Tweet.Types import Web.Tweet.Utils@@ -53,7 +55,16 @@ thread contents hs idNum num filepath = do     let handleStr = concatMap (((++) " ") . ((++) "@")) hs     let content = (take num) . (chunksOf (140-(length handleStr))) $ contents-    print $ urlString (Tweet { _status = content !! 0, _trimUser = True, _handles = hs, _replyID = idNum})+    case content of+        [] -> pure ()+        [x] -> void $ basicTweet x filepath+        (x:xs) -> do+            firstId <- basicTweet x filepath+            thread' xs hs (Just firstId) num filepath++-- | Helper function to make `thread` easier to write. +thread' :: [String] -> [String] -> Maybe Int -> Int -> FilePath -> IO ()+thread' content hs idNum num filepath = do     let f = (\str i -> (flip tweetData filepath) (Tweet { _status = str, _trimUser = True, _handles = hs, _replyID = if i == 0 then Nothing else Just i }))     let initial = f (content !! 0)     void $ foldr ((>=>) . f) initial (drop 1 content) $ maybe 0 id idNum@@ -104,7 +115,7 @@  -- | Percent-ncode the status update so it's fit for a URL tweetEncode :: Tweet -> BS.ByteString-tweetEncode tweet = paramEncode $ handleStr `BS.append` content-    where content   = BS.pack . _status $ tweet-          handleStr = BS.pack $ concatMap ((++ " ") . ((++) "@")) hs+tweetEncode tweet = paramEncode . encodeUtf8 $ handleStr `T.append` content+    where content   = T.pack . _status $ tweet+          handleStr = T.pack $ concatMap ((++ " ") . ((++) "@")) hs           hs        = _handles tweet
src/Web/Tweet/Exec.hs view
@@ -9,7 +9,7 @@ import Data.Foldable (fold)  -- | Data type for our program: one optional path to a credential file, (optionally) the number of tweets to make, the id of the status you're replying to, and a list of users you wish to mention.-data Program = Program { cred :: Maybe FilePath , tweets :: Maybe String, replyId :: Maybe String, replyHandles :: Maybe [String] }+data Program = Program { cred :: Maybe FilePath , tweets :: Maybe Int, replyId :: Maybe String, replyHandles :: Maybe [String] }  -- | query twitter to post stdin with no fancy options fromStdIn :: Int -> FilePath -> IO ()@@ -32,17 +32,18 @@  -- | Executes program select :: Program -> IO ()-select (Program Nothing (Just n) Nothing Nothing) = fromStdIn (read n) ".cred"+select (Program Nothing (Just n) Nothing Nothing) = fromStdIn n ".cred" select (Program Nothing Nothing Nothing Nothing) = fromStdIn 4 ".cred"-select (Program (Just file) (Just n) Nothing Nothing) = fromStdIn (read n) file+select (Program (Just file) (Just n) Nothing Nothing) = fromStdIn n file select (Program (Just file) Nothing Nothing Nothing) = fromStdIn 4 file-select (Program Nothing (Just n) (Just id) (Just handles)) = threadStdIn handles (read id) (read n) ".cred"-select (Program (Just file) (Just n) (Just id) (Just handles)) = threadStdIn handles (pure . read $ id) (read n) file+select (Program Nothing (Just n) (Just id) (Just handles)) = threadStdIn handles (read id) n ".cred"+select (Program (Just file) (Just n) (Just id) (Just handles)) = threadStdIn handles (pure . read $ id) n file select (Program (Just file) Nothing (Just id) (Just handles)) = threadStdIn handles (pure . read $ id) 4 file-select (Program Nothing (Just n) (Just id) Nothing) = threadStdIn [] (pure . read $ id) (read n) ".cred"+select (Program Nothing (Just n) (Just id) Nothing) = threadStdIn [] (pure . read $ id) n ".cred" select (Program Nothing Nothing (Just id) Nothing) = threadStdIn [] (pure . read $ id) 4 ".cred" select (Program Nothing Nothing (Just id) (Just handles)) = threadStdIn handles (pure . read $ id) 4 ".cred"-select (Program (Just file) (Just n) (Just id) Nothing) = threadStdIn [] (pure . read $ id) (read n) file+select (Program (Just file) (Just n) (Just id) Nothing) = threadStdIn [] (pure . read $ id) n file+select (Program (Just file) (Just n) Nothing (Just handles)) = threadStdIn handles Nothing n file  -- | Parser to return a program datatype program :: Parser Program@@ -52,7 +53,7 @@         <> short 'c'         <> metavar "CREDENTIALS"         <> help "path to credentials"))-    <*> (optional $ strOption+    <*> (optional $ read <$> strOption         (long "tweets"         <> short 't'         <> metavar "NUM"