clit 0.4.0.5 → 0.4.0.6
raw patch · 5 files changed
+45/−11 lines, 5 filesdep ~clit
Dependency ranges changed: clit
Files
- README.md +6/−0
- clit.cabal +3/−2
- src/Web/Tweet/Types.hs +13/−0
- src/Web/Tweet/Utils.hs +11/−9
- src/Web/Tweet/Utils/Colors.hs +12/−0
README.md view
@@ -78,9 +78,11 @@ The directory `bash/` has a `mkCompletions` script to allow command completions for your convenice. ## Library+ A haskell package is included. It's fairly easy to use once you have the credentials set up, with two main functions: `thread` and `basicTweet`: the first for threading your own tweets or replying to someone else's and the second for just tweeting. ### Finer details+ The function `tweetData` will tweet an object of type `Tweet`. Its use is pretty self-explanatory, but how to best form `Tweet`s is not immediately obvious. `Tweet` is an instance of `Default` so you can use `def` to get an empty tweet replying to nobody and not fetching extended user data. This is especially useful if you want to use lenses and avoid ugly record syntax, e.g.@@ -90,3 +92,7 @@ ``` will give you a `Tweet` with sensible defaults and the desired text.++### Haskell++This
clit.cabal view
@@ -1,5 +1,5 @@ name: clit-version: 0.4.0.5+version: 0.4.0.6 cabal-version: >=1.10 build-type: Simple license: BSD3@@ -52,6 +52,7 @@ other-modules: Web.Tweet.Types Web.Tweet.Utils+ Web.Tweet.Utils.Colors Web.Tweet.Sign executable tweet@@ -63,7 +64,7 @@ main-is: Main.hs build-depends: base >=4.9.1.0 && <4.10,- clit >=0.4.0.5 && <0.5+ clit >=0.4.0.6 && <0.5 default-language: Haskell2010 hs-source-dirs: app
src/Web/Tweet/Types.hs view
@@ -21,7 +21,20 @@ , _replyID :: Maybe Int } deriving (Generic, Default) +-- | Data type for tweets as they are returned+data TweetEntity = TweetEntity+ { _text :: String+ , _name :: String+ , _screenName :: Maybe String+ , _tweetId :: Int+ , _isQuoteStatus :: Bool+ , _retweets :: Int+ , _favorites :: Int+ } deriving (Generic, Default)+ -- | Stores data like (name, text, favoriteCount, retweetCount) type Timeline = [(String, String, String, String)] makeLenses ''Tweet++makeLenses ''TweetEntity
src/Web/Tweet/Utils.hs view
@@ -11,10 +11,10 @@ import Data.Maybe import Web.Tweet.Types import Control.Monad-import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), char, (<>), string) import Control.Lens.Tuple import Control.Lens hiding (noneOf) import Data.Function+import Web.Tweet.Utils.Colors -- `FIXME` parseDMs = zip <$> (extractEvery 2 <$> filterStr "screen_name") <*> (filterStr "text")@@ -27,7 +27,7 @@ -- | Display Timeline in color displayTimelineColor :: Timeline -> String-displayTimelineColor ((user,content,fave,rts):rest) = ((show . yellow . text $ user) <> ":\n " <> content) <> "\n " <> (show . red . text $ "♥ ") {-- ♡💛--} <> fave <> (show . green . text $ " ♺ ") <> rts <> "\n\n" <> (displayTimelineColor rest) -- +displayTimelineColor ((user,content,fave,rts):rest) = ((toYellow user) <> ":\n " <> content) <> "\n " <> (toRed "♥ ") {-- ♡💛--} <> fave <> (toGreen " ♺ ") <> rts <> "\n\n" <> (displayTimelineColor rest) -- displayTimelineColor [] = [] -- | Get a list of tweets from a response, returning author, favorites, retweets, and content. @@ -35,7 +35,7 @@ -- | Parse some number of tweets parseTweet :: Parser Timeline-parseTweet = many (try getData <|> (const ("","","","") <$> eof))+parseTweet = concat <$> many (try getData <|> (const (pure ("","","","")) <$> eof)) hits = sortFaves . filterRTs @@ -47,24 +47,26 @@ where compareFavorites = on compare ((read :: String -> Int) . (view _3)) -- | Parse a single tweet's: name, text, fave count, retweet count-getData :: Parser (String, String, String, String)+getData :: Parser [(String, String, String, String)] getData = do text <- filterStr "text" skipMentions- --userMentions <- filterStr "user_mentions"- --name <- if userMentions == "[]" then filterStr "name" else filterStr "name" >> filterStr "name" -- FIXME fix this to read number of userMentions name <- filterStr "name" isQuote <- filterStr "is_quote_status" case isQuote of "false" -> do rts <- filterStr "retweet_count" faves <- filterStr "favorite_count"- pure (name, text, faves, rts)+ pure $ pure (name, text, faves, rts) "true" -> do+ textQuoted <- filterStr "text" skipMentions- rts <- filterStr "retweet_count" >> filterStr "retweet_count"+ nameQuoted <- filterStr "name"+ rtsQuoted <- filterStr "retweet_count"+ favesQuoted <- filterStr "favorite_count"+ rts <- filterStr "retweet_count" faves <- filterStr "favorite_count"- pure (name, text, faves, rts)+ pure [(name, text, faves, rts), (nameQuoted, textQuoted, favesQuoted, rtsQuoted)] -- TODO make it work when user names include ] skipInsideBrackets :: Parser ()
+ src/Web/Tweet/Utils/Colors.hs view
@@ -0,0 +1,12 @@+module Web.Tweet.Utils.Colors where++import Text.PrettyPrint.ANSI.Leijen++toRed :: String -> String+toRed = show . red . text++toYellow :: String -> String+toYellow = show . yellow . text++toGreen :: String -> String+toGreen = show . green . text