Browse Source

[WIP] Try to build a ArtDecoCardElement Node first

jherve 1 năm trước cách đây
mục cha
commit
cea51a93e4
3 tập tin đã thay đổi với 55 bổ sung0 xóa
  1. 3 0
      src/Content.purs
  2. 40 0
      src/LinkedIn/ArtDecoCardAlt.purs
  3. 12 0
      src/LinkedIn/Types.purs

+ 3 - 0
src/Content.purs

@@ -12,6 +12,7 @@ import Effect (Effect)
 import Effect.Class.Console (logShow)
 import Effect.Console (log)
 import LinkedIn.ArtDecoCard (parseArtDecoCard)
+import LinkedIn.ArtDecoCardAlt (queryArtDecoCardAlt)
 import LinkedIn.ArtDecoTab (parseArtDecoTab)
 import LinkedIn.JobsUnifiedTopCard (parseJobsUnifiedTopCardElement)
 import LinkedIn.Profile.Project as PP
@@ -38,8 +39,10 @@ main = do
   case artDecoCards of
     Nothing -> log "nothing"
     Just l -> do
+      queried <- (\(LinkedInUIElement _ n) -> queryArtDecoCardAlt n) $ NEL.head l
       parsed <- (\(LinkedInUIElement _ n) -> parseArtDecoCard n) $ NEL.head l
       logShow parsed
+      logShow queried
       case parsed of
         Left l -> logShow l
         Right p -> do

+ 40 - 0
src/LinkedIn/ArtDecoCardAlt.purs

@@ -0,0 +1,40 @@
+module LinkedIn.ArtDecoCardAlt where
+
+import Prelude
+
+import Data.Either (note)
+import Data.Generic.Rep (class Generic)
+import Data.List (List)
+import Data.List.Types (NonEmptyList)
+import Data.Maybe (Maybe)
+import Data.Show.Generic (genericShow)
+import LinkedIn (DetachedNode)
+import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
+import LinkedIn.ArtDeco as AD
+import LinkedIn.Types (Parser, QueryError(..), QueryRunner)
+import LinkedIn.Utils (queryOne, queryOneAndParse)
+import Web.DOM (Node)
+import Web.DOM.Node (nodeName)
+
+
+data ArtDecoCardAltElement a = ArtDecoCardAltElement {
+  pvs_entity :: a
+}
+
+derive instance Generic (ArtDecoCardAltElement a) _
+derive instance Eq a => Eq (ArtDecoCardAltElement a)
+instance Show (ArtDecoCardAltElement Node) where
+  show (ArtDecoCardAltElement {pvs_entity}) = "ArtDecoCardAltElement(Node " <> nodeName pvs_entity <> ")"
+else instance Show a => Show (ArtDecoCardAltElement a) where
+  show = genericShow
+instance Functor ArtDecoCardAltElement where
+  map f (ArtDecoCardAltElement {pvs_entity}) =
+    ArtDecoCardAltElement ({pvs_entity: f pvs_entity})
+
+queryArtDecoCardAlt :: QueryRunner (ArtDecoCardAltElement Node)
+queryArtDecoCardAlt n = do
+  pvs <- queryOne ":scope div.pvs-entity--padded" n
+
+  pure $ ado
+    p <- note (QNodeNotFoundError "stuff") pvs
+  in ArtDecoCardAltElement {pvs_entity: p}

+ 12 - 0
src/LinkedIn/Types.purs

@@ -19,3 +19,15 @@ instance Show ParseError where
   show = genericShow
 
 type Parser a = Node → Effect (Either ParseError a)
+
+data QueryError =
+  QNodeNotFoundError String
+  | QNodeListNotFoundError String
+  | QTextNotFoundError
+
+derive instance Generic QueryError _
+derive instance Eq QueryError
+instance Show QueryError where
+  show = genericShow
+
+type QueryRunner a = Node → Effect (Either QueryError a)