This commit is contained in:
Yann Esposito 2015-08-12 10:07:50 +02:00
parent 0e86dd4e8e
commit 74dede2664
2 changed files with 36 additions and 32 deletions

10
.dir-locals.el Normal file
View file

@ -0,0 +1,10 @@
((haskell-mode
. ((haskell-indent-spaces . 4)
(hindent-style . "johan-tibell")
(haskell-process-type . ghci)
(haskell-process-path-ghci . "stack")
(haskell-process-args-ghci . ("ghci"))))
(haskell-cabal-mode
. ((haskell-process-type . ghci)
(haskell-process-path-ghci . "stack")
(haskell-process-args-ghci . ("ghci")))))

View file

@ -35,17 +35,15 @@ displayAndResetCounter seconds threshold counter nullSecCounter = do
then void $ incrCounter 1 nullSecCounter
else writeCounter nullSecCounter 0
nullSec <- readCounter nullSecCounter
if nullSec > 0
then warningM "Lotwittery.Counter" $ show nb <> " "
when nullSec > 0 (warningM "Lotwittery.Counter" $ show nb <> " "
<> show nullSec
<> " seconds with not enough tweet < "
<> show threshold
else return ()
<> show threshold)
writeCounter counter 0
threadDelay $ 1000000 * seconds
leeting' :: Set Text -> (Text -> Text) -> Set Text
leeting' s f = Set.map (\t -> f t) s
leeting' s f = Set.map f s
-- | List of transformation function
-- TODO: make a replaceFirstOccurence instead of T.replace
@ -75,7 +73,7 @@ fixpoint f initialValue = converge (==) (iterate f initialValue)
converge _ _ = error "You've reached the impossible"
applyAllTransform :: Set Text -> Set Text
applyAllTransform s = mconcat (map (\f -> Set.map f s) trfunctions)
applyAllTransform s = mconcat (map (filp Set.map s) trfunctions)
leetify :: Text -> [Text]
leetify t =
@ -108,14 +106,14 @@ favorite :: OAuthConf -> Text -> IO ()
favorite oauth tweet_id = do
putStrLn ("Favorite: " <> tweet_id)
let b_tweet_id = B.pack (T.unpack tweet_id)
post oauth ("/favorites/create.json") [("id",b_tweet_id)]
post oauth "/favorites/create.json" [("id",b_tweet_id)]
-- | Follow an user
follow :: OAuthConf -> Text -> IO ()
follow oauth user_id = do
putStrLn ("Follow: " <> user_id)
let b_user_id = B.pack (T.unpack user_id)
post oauth ("/friendships/create.json") [("user_id",b_user_id)]
post oauth "/friendships/create.json" [("user_id",b_user_id)]
--------------------------------------------------------------------------------
@ -123,7 +121,7 @@ matchSubs :: Text -> Text -> Bool
matchSubs m t = not ( T.null ( snd (T.breakOn m (t <> " "))))
manualRT :: Text -> Bool
manualRT t = case (P.parse manualRTParser "" t) of
manualRT t = case P.parse manualRTParser "" t of
Left _ -> False
Right _ -> True
where
@ -133,7 +131,7 @@ manualRT t = case (P.parse manualRTParser "" t) of
P.char ':'
manualRT2 :: Text -> Bool
manualRT2 t = case (P.parse manualRTParser "" t) of
manualRT2 t = case P.parse manualRTParser "" t of
Left _ -> False
Right _ -> True
where
@ -144,7 +142,7 @@ manualRT2 t = case (P.parse manualRTParser "" t) of
--------------------------------------------------------------------------------
matchFollow :: Text -> Bool
matchFollow t = any (\m -> matchSubs m l) mandatories
matchFollow t = any (`matchSubs` l) mandatories
&& all (\m -> not (matchSubs m l)) stopwords
where
l = T.toLower t
@ -164,9 +162,9 @@ searchKeywordsTwitter = T.unpack (intercalate "," searchKeywords)
--------------------------------------------------------------------------------
matchRT :: Text -> Bool
matchRT t = any (\m -> matchSubs m l) mandatories
matchRT t = any (`matchSubs` l) mandatories
&& all (\m -> not (matchSubs m l)) stopwords
&& not (any (== (T.last l)) ['0','1','2','3','4','5','6','7','8','9'])
&& notElem (T.last l) ['0'..'9']
&& not (manualRT l)
&& not (manualRT2 l)
where
@ -182,25 +180,22 @@ matchRT t = any (\m -> matchSubs m l) mandatories
smartFollow :: OAuthConf -> Text -> Text -> Text -> IO ()
smartFollow oauth user_id user_url t =
if not (T.null user_url) && matchRT t && matchFollow t
then do
putStrLn "Follow"
_ <- forkIO $ threadDelay (1000000 * 10) >> follow oauth user_id
return ()
else return ()
when (not (T.null user_url) && matchRT t && matchFollow t)
(do
putStrLn "Follow"
_ <- forkIO $ threadDelay (1000000 * 10) >> follow oauth user_id
return ())
smartRT :: OAuthConf -> Text -> Text -> Text -> IO ()
smartRT oauth tweet_id user_url t =
if not (T.null user_url) && matchRT t
then do
when (not (T.null user_url) && matchRT t)
(do
putStrLn "RT & Fav"
_ <- forkIO $ do
threadDelay (100000 * 5)
retweet oauth (T.unpack tweet_id)
threadDelay (1000000 * 1)
threadDelay (10^6)
favorite oauth tweet_id
return ()
else return ()
return ())
isntRT :: Text -> Bool
isntRT t = (T.take 1 t /= "@") && (T.take 2 t /= "RT") && (T.take 3 t /= "via")
@ -213,13 +208,12 @@ handleOneTweet oauth counter tweet = do
case retweet_status of
Just _ -> return ()
Nothing -> case text of
Just (String t) -> if isntRT t
then do
putStrLn (tweet_id <> ": " <> (T.replace "\n" " " t))
smartRT oauth tweet_id user_url t
smartFollow oauth user_id user_url t
return ()
else return ()
Just (String t) -> when (isntRT t)
(do
putStrLn (tweet_id <> ": " <> T.replace "\n" " " t)
smartRT oauth tweet_id user_url t
smartFollow oauth user_id user_url t
return ())
_ -> return ()
where