packages feed

clit 0.3.0.3 → 0.3.1.0

raw patch · 6 files changed

+46/−24 lines, 6 filesdep +directorydep ~clit

Dependencies added: directory

Dependency ranges changed: clit

Files

README.md view
@@ -3,7 +3,7 @@ ## Config Generate a token to authorize access to your twitter account by following the guide [here](https://dev.twitter.com/oauth/overview/application-owner-access-tokens) -Then place your API keys and OAuth tokens in a file `.cred`, separated by a line break:+Then place your API keys and OAuth tokens in a file `~/.cred`, separated by a line break:  ``` api-key: API_KEY_HERE
bash/example view
@@ -1,1 +1,1 @@-stack install 2&>1 >/dev/null | tweet -c .cred -t3+stack install 2&>1 >/dev/null | tweet -c ~/.cred send -t3
clit.cabal view
@@ -1,5 +1,5 @@ name: clit-version: 0.3.0.3+version: 0.3.1.0 cabal-version: >=1.10 build-type: Simple license: BSD3@@ -47,7 +47,8 @@         text >=1.2.2.1 && <1.3,         megaparsec >=5.2.0 && <5.3,         ansi-wl-pprint >=0.6.7.3 && <0.7,-        MissingH >=1.4.0.1 && <1.5+        MissingH >=1.4.0.1 && <1.5,+        directory >=1.3.0.0 && <1.4     default-language: Haskell2010     hs-source-dirs: src     other-modules:@@ -64,7 +65,7 @@     main-is: Main.hs     build-depends:         base >=4.9.1.0 && <4.10,-        clit >=0.3.0.3 && <0.4+        clit >=0.3.1.0 && <0.4     default-language: Haskell2010     hs-source-dirs: app 
src/Web/Tweet.hs view
@@ -32,6 +32,8 @@     , showTimeline     , getProfile     , showProfile+    , getDMs+    , showDMs     ) where  import Network.HTTP.Client@@ -65,16 +67,16 @@         Nothing -> case content of             [] -> pure ()             [x] -> void $ basicTweet x filepath-            (x:xs) -> do-                firstId <- basicTweet x filepath-                thread' xs hs (Just firstId) num filepath+            y@(x:xs) -> do+                thread' y hs (Just 0) 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 -> tweetData (Tweet { _status = str, _trimUser = True, _handles = hs, _replyID = if i == 0 then Nothing else Just i }) filepath     let initial = f (head content)-    void $ foldr ((>=>) . f) initial (reverse . drop 1 $ content) $ fromMaybe 0 idNum+    last <- foldr ((>=>) . f) initial (content) $ fromMaybe 0 idNum+    deleteTweet last filepath  -- | Reply with a single tweet. Works the same as `thread` but doesn't take the fourth argument. --@@ -108,19 +110,34 @@     request <- signRequest filepath $ initialRequest { method = "GET"}     getTweets . BSL.unpack <$> responseBS request manager +showDMs count color filepath = showTweets color <$> getDMs count filepath+ showProfile screenName count color filepath = showTweets color <$> getProfile screenName count filepath  showTimeline count color filepath = showTweets color <$> getTimeline count filepath -showTweets color = replace "\\n" "\n" . replace "\\/" "/" . fromRight . (fmap (if color then displayTimelineColor else displayTimeline))+showTweets color = {-- replace "\\n" "\n" . --} replace "\\/" "/" . fromRight . (fmap (if color then displayTimelineColor else displayTimeline))     where fromRight (Right a) = a +getDMs count filepath = do+    let requestString = "?count=" ++ (show count)+    manager <- newManager tlsManagerSettings+    initialRequest <- parseRequest ("https://api.twitter.com/1.1/direct_messages.json" ++ requestString)+    request <- signRequest filepath $ initialRequest { method = "GET" }+    getTweets . BSL.unpack <$> responseBS request manager+ getTimeline count filepath = do     let requestString = "?count=" ++ (show count)     manager <- newManager tlsManagerSettings     initialRequest <- parseRequest ("https://api.twitter.com/1.1/statuses/home_timeline.json" ++ requestString)     request <- signRequest filepath $ initialRequest { method = "GET" }     getTweets . BSL.unpack <$> responseBS request manager++deleteTweet id filepath = do+    manager <- newManager tlsManagerSettings+    initialRequest <- parseRequest ("https://api.twitter.com/1.1/statuses/destroy/" ++ (show id) ++ ".json")+    request <- signRequest filepath $ initialRequest { method = "GET" }+    void $ responseBS request manager  responseBS :: Request -> Manager -> IO BSL.ByteString responseBS request manager = do
src/Web/Tweet/Exec.hs view
@@ -8,6 +8,7 @@ import Control.Monad import Data.Foldable (fold) import Data.Monoid+import System.Directory  -- | 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 { subcommand :: Command , cred :: Maybe FilePath }@@ -35,34 +36,34 @@  -- | Executes program select :: Program -> IO ()-select (Program (Send (Just n) Nothing Nothing) Nothing) = fromStdIn n ".cred"-select (Program (Send Nothing Nothing Nothing) Nothing) = fromStdIn 4 ".cred"+select (Program (Send (Just n) Nothing Nothing) Nothing) = fromStdIn n =<< (++ "/.cred") <$> getHomeDirectory+select (Program (Send Nothing Nothing Nothing) Nothing) = fromStdIn 4  =<< (++ "/.cred") <$> getHomeDirectory select (Program (Send (Just n) Nothing Nothing) (Just file))  = fromStdIn n file select (Program (Send Nothing Nothing Nothing) (Just file) ) = fromStdIn 4 file-select (Program (Send (Just n) (Just id) (Just handles)) Nothing) = threadStdIn handles (read id) n ".cred"+select (Program (Send (Just n) (Just id) (Just handles)) Nothing) = threadStdIn handles (read id) n  =<< (++ "/.cred") <$> getHomeDirectory select (Program (Send (Just n) (Just id) (Just handles)) (Just file)) = threadStdIn handles (pure . read $ id) n file select (Program (Send Nothing (Just id) (Just handles)) (Just file))  = threadStdIn handles (pure . read $ id) 4 file-select (Program (Send (Just n) (Just id) Nothing) Nothing) = threadStdIn [] (pure . read $ id) n ".cred"-select (Program (Send Nothing (Just id) Nothing) Nothing) = threadStdIn [] (pure . read $ id) 4 ".cred"-select (Program (Send Nothing (Just id) (Just handles)) Nothing) = threadStdIn handles (pure . read $ id) 4 ".cred"+select (Program (Send (Just n) (Just id) Nothing) Nothing) = threadStdIn [] (pure . read $ id) n  =<< (++ "/.cred") <$> getHomeDirectory+select (Program (Send Nothing (Just id) Nothing) Nothing) = threadStdIn [] (pure . read $ id) 4  =<< (++ "/.cred") <$> getHomeDirectory+select (Program (Send Nothing (Just id) (Just handles)) Nothing) = threadStdIn handles (pure . read $ id) 4  =<< (++ "/.cred") <$> getHomeDirectory select (Program (Send (Just n) (Just id) Nothing) (Just file)) = threadStdIn [] (pure . read $ id) n file select (Program (Send (Just n) Nothing (Just handles)) (Just file)) = threadStdIn handles Nothing n file-select (Program (Timeline Nothing False) Nothing) = putStrLn =<< showTimeline 8 False ".cred"+select (Program (Timeline Nothing False) Nothing) = putStrLn =<< showTimeline 8 False  =<< (++ "/.cred") <$> getHomeDirectory select (Program (Timeline Nothing False) (Just file)) = putStrLn =<< showTimeline 8 False file select (Program (Timeline (Just n) False) (Just file)) = putStrLn =<< showTimeline 8 False file-select (Program (Timeline (Just n) False) Nothing) = putStrLn =<< showTimeline 8 False ".cred"-select (Program (Timeline Nothing True) Nothing) = putStrLn =<< showTimeline 8 True ".cred"+select (Program (Timeline (Just n) False) Nothing) = putStrLn =<< showTimeline 8 False  =<< (++ "/.cred") <$> getHomeDirectory+select (Program (Timeline Nothing True) Nothing) = putStrLn =<< showTimeline 8 True  =<< (++ "/.cred") <$> getHomeDirectory select (Program (Timeline Nothing True) (Just file)) = putStrLn =<< showTimeline 8 True file select (Program (Timeline (Just n) True) (Just file)) = putStrLn =<< showTimeline 8 True file-select (Program (Timeline (Just n) True) Nothing) = putStrLn =<< showTimeline 8 True ".cred"+select (Program (Timeline (Just n) True) Nothing) = putStrLn =<< showTimeline 8 True  =<< (++ "/.cred") <$> getHomeDirectory select (Program (Profile (Just n) True name) (Just file)) = putStrLn =<< showProfile name n True file select (Program (Profile Nothing True name) (Just file)) = putStrLn =<< showProfile name 12 True file-select (Program (Profile (Just n) True name) Nothing) = putStrLn =<< showProfile name n True ".cred"-select (Program (Profile Nothing True name) Nothing) = putStrLn =<< showProfile name 12 True ".cred"+select (Program (Profile (Just n) True name) Nothing) = putStrLn =<< showProfile name n True  =<< (++ "/.cred") <$> getHomeDirectory+select (Program (Profile Nothing True name) Nothing) = putStrLn =<< showProfile name 12 True  =<< (++ "/.cred") <$> getHomeDirectory select (Program (Profile (Just n) False name) (Just file)) = putStrLn =<< showProfile name n False file select (Program (Profile Nothing False name) (Just file)) = putStrLn =<< showProfile name 12 False file-select (Program (Profile (Just n) False name) Nothing) = putStrLn =<< showProfile name n False ".cred"-select (Program (Profile Nothing False name) Nothing) = putStrLn =<< showProfile name 12 False ".cred"+select (Program (Profile (Just n) False name) Nothing) = putStrLn =<< showProfile name n False  =<< (++ "/.cred") <$> getHomeDirectory+select (Program (Profile Nothing False name) Nothing) = putStrLn =<< showProfile name 12 False  =<< (++ "/.cred") <$> getHomeDirectory  -- | Parser to return a program datatype program :: Parser Program
src/Web/Tweet/Utils.hs view
@@ -15,6 +15,9 @@ --toUnicode :: Parser String --toUnicode "\u00e9" =  +parseDMs = zip <$> (extractEvery 2 <$> filterStr "screen_name") <*> (filterStr "text")+    where extractEvery n = map snd . filter ((== n) . fst) . zip (cycle [1..n])+ displayTimelineColor :: Timeline -> String displayTimelineColor ((user,content):rest) = ((show . yellow . text $ user) <> ":\n    " <> content <> "\n") <> (displayTimelineColor rest) displayTimelineColor [] = []