packages feed

tellbot 0.5.1.1 → 0.5.1.2

raw patch · 4 files changed

+39/−2 lines, 4 files

Files

CHANGELOG.md view
@@ -1,6 +1,10 @@ tellbot CHANGELOG ================= +### 0.5.1.2++- added HTML in other-modules (doesn’t compile otherwise)+ ### 0.5.1.1  - patch for old GHC versions (fixes uses of pure)
+ src/HTML.hs view
@@ -0,0 +1,32 @@+module HTML where++import Control.Applicative ( pure )+import Control.Exception ( SomeException, catch )+import Control.Monad ( guard )+import Data.List ( isPrefixOf )+import Network.HTTP.Conduit+import Text.Regex.Posix ( (=~) )++htmlTitle :: String -> IO (Maybe String)+htmlTitle url = do+    -- test http; if it fails, test https+    http <- flip catch handleException $ fmap (extractTitle . show) $ simpleHttp httpPrefixedURL+    case http of+      Just _ -> pure http+      Nothing -> flip catch handleException $ fmap (extractTitle . show) $ simpleHttp httpsPrefixedURL+  where+    httpPrefixedURL = if "http://" `isPrefixOf` url then url else "http://" ++ url+    httpsPrefixedURL = if "https://" `isPrefixOf` url then url else "https://" ++ url+    handleException :: SomeException -> IO (Maybe String)+    handleException _ = pure Nothing+    +extractTitle :: String -> Maybe String+extractTitle body = do+    guard (not $ null titleHTML)+    pure $ dropAround (length "<title>") (length "</title>") titleHTML+  where+    titleHTML :: String+    titleHTML = body =~ "<title>[^<]*</title>"++dropAround :: Int -> Int -> String -> String+dropAround s e = reverse . drop e . reverse . drop s
src/Main.hs view
@@ -20,7 +20,7 @@ import System.IO  version :: Version-version = Version [0,5,1,0] ["Apfelschorle"]+version = Version [0,5,1,2] ["Apfelschorle"]  type Failable   = EitherT String Identity type FailableIO = EitherT String IO
tellbot.cabal view
@@ -1,5 +1,5 @@ name:                tellbot-version:             0.5.1.1+version:             0.5.1.2 synopsis:            IRC tellbot description:         An IRC bot that can be used to create queuing message.                      It also offers a simple administration IRC bot interface.@@ -20,6 +20,7 @@ executable tellbot   main-is:             Main.hs +  other-modules:       HTML   default-extensions:  FlexibleInstances    build-depends:       base         >= 4.5  && < 5