packages feed

advent-of-code-api 0.1.2.0 → 0.1.2.1

raw patch · 3 files changed

+36/−37 lines, 3 filesdep +tagsoupdep −taggyPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependencies added: tagsoup

Dependencies removed: taggy

API changes (from Hackage documentation)

+ Advent: processHTML :: String -> [Text]

Files

CHANGELOG.md view
@@ -1,6 +1,16 @@ Changelog ========= +Version 0.1.2.1+---------------++*December 8, 2018*++<https://github.com/mstksg/advent-of-code-api/releases/tag/v0.1.2.1>++*   *BUGFIX* Switched from *taggy* to *tagsoup*, after observing that *taggy*+    had some issues parsing 2018's Day 8 challenge prompt.+ Version 0.1.2.0 --------------- 
advent-of-code-api.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 65e4e6828d9edc4bd8f8bb184773083c933cec327f7b7bcfaac1f90e763cf296+-- hash: d32ac9493495ca401a31da403484b15234aed2d00cc9267787c63475db1acee2  name:           advent-of-code-api-version:        0.1.2.0+version:        0.1.2.1 synopsis:       Advent of Code REST API bindings description:    Haskell bindings for Advent of Code REST API.  Please use responsibly!                 See README.md or "Advent" module for an introduction and tutorial.@@ -60,7 +60,7 @@     , filepath     , finite-typelits     , mtl-    , taggy+    , tagsoup     , text     , time     , uri-encode
src/Advent.hs view
@@ -67,6 +67,7 @@   , setAoCThrottleLimit, getAoCThrottleLimit   -- * Internal   , parseSubmitRes+  , processHTML   ) where  import           Advent.Cache@@ -78,26 +79,26 @@ import           Data.Finite import           Data.Foldable import           Data.Kind-import           Data.Map             (Map)+import           Data.Map               (Map) import           Data.Maybe-import           Data.Semigroup-import           Data.Set             (Set)-import           Data.Text            (Text)+import           Data.Set               (Set)+import           Data.Text              (Text) import           Data.Time import           Data.Typeable-import           GHC.Generics         (Generic)+import           GHC.Generics           (Generic) import           Network.Curl import           System.Directory import           System.FilePath+import           Text.HTML.TagSoup.Tree (TagTree(..)) import           Text.Printf-import qualified Data.Attoparsec.Text as P-import qualified Data.Map             as M-import qualified Data.Set             as S-import qualified Data.Text            as T-import qualified Data.Text.Lazy       as TL-import qualified Network.URI.Encode   as URI-import qualified System.IO.Unsafe     as Unsafe-import qualified Text.Taggy           as H+import qualified Data.Attoparsec.Text   as P+import qualified Data.Map               as M+import qualified Data.Set               as S+import qualified Data.Text              as T+import qualified Network.URI.Encode     as URI+import qualified System.IO.Unsafe       as Unsafe+import qualified Text.HTML.TagSoup      as H+import qualified Text.HTML.TagSoup.Tree as H  initialThrottleLimit :: Int initialThrottleLimit = 100@@ -339,18 +340,16 @@                  . processHTML  -- | Process an HTML webpage into a list of all contents in <article>s-processHTML :: String -> [T.Text]-processHTML = map (TL.toStrict . TL.intercalate "\n" . map H.render)+processHTML :: String -> [Text]+processHTML = map H.renderTree             . mapMaybe isArticle-            . foldMap universe-            . listToMaybe-            . H.parseDOM True-            . TL.pack+            . H.universeTree+            . H.parseTree+            . T.pack   where-    isArticle (H.NodeElement H.Element{..})-        = eltChildren <$ guard (eltName == "article")-    isArticle _-        = Nothing+    isArticle :: TagTree Text -> Maybe [TagTree Text]+    isArticle (TagBranch n _ ts) = ts <$ guard (n == "article")+    isArticle _                  = Nothing  -- | Parse 'Text' into a 'SubmitRes'. parseSubmitRes :: Text -> SubmitRes@@ -358,8 +357,7 @@                . P.parseOnly choices                . mconcat                . mapMaybe deTag-               . H.taggyWith True-               . TL.fromStrict+               . H.parseTags   where     deTag (H.TagText t) = Just t     deTag _             = Nothing@@ -451,15 +449,6 @@ mkDay_ = fromMaybe e . mkDay   where     e = errorWithoutStackTrace "Advent.mkDay_: Date out of range (1 - 25)"---- | All nodes within a node.-universe :: H.Node -> [H.Node]-universe = ($ []) . appEndo . go-  where-    go :: H.Node -> Endo [H.Node]-    go (H.NodeElement (H.Element{..})) = Endo (eltChildren ++)-                                      <> foldMap go eltChildren-    go (H.NodeContent _              ) = mempty  -- | Get time until release of a given challenge. timeToRelease