소스 검색

Start composing queries

jherve 1 년 전
부모
커밋
ebc60bae81
2개의 변경된 파일16개의 추가작업 그리고 8개의 파일을 삭제
  1. 2 2
      src/Content.purs
  2. 14 6
      src/LinkedIn/ArtDecoCardAlt.purs

+ 2 - 2
src/Content.purs

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

+ 14 - 6
src/LinkedIn/ArtDecoCardAlt.purs

@@ -79,16 +79,24 @@ instance Traversable ArtDecoCardAltElement where
 
   traverse = \x -> traverseDefault x
 
-queryArtDecoCardAlt :: Node → Effect (Either QueryError (ArtDecoCardAltElement Node))
-queryArtDecoCardAlt n = runExceptT do
-  pvs <- runOne ":scope div.pvs-entity--padded" n
-
-  bold <- runOne ":scope div.t-bold > span[aria-hidden=true]" pvs
+queryArtDecoCenterHeaderAlt ∷ Node → ExceptT QueryError Effect (ArtDecoCenterHeaderAlt Node)
+queryArtDecoCenterHeaderAlt n = do
+  bold <- runOne ":scope div.t-bold > span[aria-hidden=true]" n
   normal <-
     ignoreNotFound $
     runOne ":scope span.t-normal:not(t-black--light) > span[aria-hidden=true]" n
 
-  pure $ ArtDecoCardAltElement { pvs_entity: ArtDecoCenterHeaderAlt {bold, normal: normal} }
+  pure $ ArtDecoCenterHeaderAlt {bold, normal: normal}
+
+queryArtDecoCardAlt ∷ Node → ExceptT QueryError Effect (ArtDecoCardAltElement Node)
+queryArtDecoCardAlt n = do
+  pvs <- runOne ":scope div.pvs-entity--padded" n
+  header <- queryArtDecoCenterHeaderAlt pvs
+
+  pure $ ArtDecoCardAltElement { pvs_entity: header }
+
+runQuery ∷ ∀ a. ExceptT QueryError Effect a → Effect (Either QueryError a)
+runQuery = runExceptT
 
 ignoreNotFound ∷ ∀ a f. Functor f ⇒ ExceptT QueryError f a → ExceptT QueryError f (Maybe a)
 ignoreNotFound = mapExceptT (map ignoreNotFound')