+35
-36
lines changedFilter options
+35
-36
lines changed Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
1
1
Changelog
2
2
=========
3
3
4
+
Version 0.1.2.1
5
+
---------------
6
+
7
+
*December 8, 2018*
8
+
9
+
<https://github.com/mstksg/advent-of-code-api/releases/tag/v0.1.2.1>
10
+
11
+
* *BUGFIX* Switched from *taggy* to *tagsoup*, after observing that *taggy*
12
+
had some issues parsing 2018's Day 8 challenge prompt.
13
+
4
14
Version 0.1.2.0
5
15
---------------
6
16
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1
1
name: advent-of-code-api
2
-
version: 0.1.2.0
2
+
version: 0.1.2.1
3
3
github: "mstksg/advent-of-code-api"
4
4
license: BSD3
5
5
author: "Justin Le"
@@ -44,7 +44,7 @@ library:
44
44
- deepseq
45
45
- finite-typelits
46
46
- mtl
47
-
- taggy
47
+
- tagsoup
48
48
- time
49
49
- uri-encode
50
50
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@ module Advent (
67
67
, setAoCThrottleLimit, getAoCThrottleLimit
68
68
-- * Internal
69
69
, parseSubmitRes
70
+
, processHTML
70
71
) where
71
72
72
73
import Advent.Cache
@@ -78,26 +79,26 @@ import Data.Char
78
79
import Data.Finite
79
80
import Data.Foldable
80
81
import Data.Kind
81
-
import Data.Map (Map)
82
+
import Data.Map (Map)
82
83
import Data.Maybe
83
-
import Data.Semigroup
84
-
import Data.Set (Set)
85
-
import Data.Text (Text)
84
+
import Data.Set (Set)
85
+
import Data.Text (Text)
86
86
import Data.Time
87
87
import Data.Typeable
88
-
import GHC.Generics (Generic)
88
+
import GHC.Generics (Generic)
89
89
import Network.Curl
90
90
import System.Directory
91
91
import System.FilePath
92
+
import Text.HTML.TagSoup.Tree (TagTree(..))
92
93
import Text.Printf
93
-
import qualified Data.Attoparsec.Text as P
94
-
import qualified Data.Map as M
95
-
import qualified Data.Set as S
96
-
import qualified Data.Text as T
97
-
import qualified Data.Text.Lazy as TL
98
-
import qualified Network.URI.Encode as URI
99
-
import qualified System.IO.Unsafe as Unsafe
100
-
import qualified Text.Taggy as H
94
+
import qualified Data.Attoparsec.Text as P
95
+
import qualified Data.Map as M
96
+
import qualified Data.Set as S
97
+
import qualified Data.Text as T
98
+
import qualified Network.URI.Encode as URI
99
+
import qualified System.IO.Unsafe as Unsafe
100
+
import qualified Text.HTML.TagSoup as H
101
+
import qualified Text.HTML.TagSoup.Tree as H
101
102
102
103
initialThrottleLimit :: Int
103
104
initialThrottleLimit = 100
@@ -339,27 +340,24 @@ processAoC = \case
339
340
. processHTML
340
341
341
342
-- | Process an HTML webpage into a list of all contents in <article>s
342
-
processHTML :: String -> [T.Text]
343
-
processHTML = map (TL.toStrict . TL.intercalate "\n" . map H.render)
343
+
processHTML :: String -> [Text]
344
+
processHTML = map H.renderTree
344
345
. mapMaybe isArticle
345
-
. foldMap universe
346
-
. listToMaybe
347
-
. H.parseDOM True
348
-
. TL.pack
346
+
. H.universeTree
347
+
. H.parseTree
348
+
. T.pack
349
349
where
350
-
isArticle (H.NodeElement H.Element{..})
351
-
= eltChildren <$ guard (eltName == "article")
352
-
isArticle _
353
-
= Nothing
350
+
isArticle :: TagTree Text -> Maybe [TagTree Text]
351
+
isArticle (TagBranch n _ ts) = ts <$ guard (n == "article")
352
+
isArticle _ = Nothing
354
353
355
354
-- | Parse 'Text' into a 'SubmitRes'.
356
355
parseSubmitRes :: Text -> SubmitRes
357
356
parseSubmitRes = either SubUnknown id
358
357
. P.parseOnly choices
359
358
. mconcat
360
359
. mapMaybe deTag
361
-
. H.taggyWith True
362
-
. TL.fromStrict
360
+
. H.parseTags
363
361
where
364
362
deTag (H.TagText t) = Just t
365
363
deTag _ = Nothing
@@ -452,15 +450,6 @@ mkDay_ = fromMaybe e . mkDay
452
450
where
453
451
e = errorWithoutStackTrace "Advent.mkDay_: Date out of range (1 - 25)"
454
452
455
-
-- | All nodes within a node.
456
-
universe :: H.Node -> [H.Node]
457
-
universe = ($ []) . appEndo . go
458
-
where
459
-
go :: H.Node -> Endo [H.Node]
460
-
go (H.NodeElement (H.Element{..})) = Endo (eltChildren ++)
461
-
<> foldMap go eltChildren
462
-
go (H.NodeContent _ ) = mempty
463
-
464
453
-- | Get time until release of a given challenge.
465
454
timeToRelease
466
455
:: Integer -- ^ year
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4