瀏覽代碼

Extract information from job first insight

jherve 1 年之前
父節點
當前提交
2e8f2a280e
共有 2 個文件被更改,包括 29 次插入4 次删除
  1. 20 3
      src/LinkedIn/Jobs/JobOffer.purs
  2. 9 1
      src/LinkedIn/JobsUnifiedTopCard.purs

+ 20 - 3
src/LinkedIn/Jobs/JobOffer.purs

@@ -4,16 +4,18 @@ import Prelude
 
 import Data.Either (Either, note)
 import Data.Generic.Rep (class Generic)
+import Data.Lens (findOf)
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
-import LinkedIn.JobsUnifiedTopCard (JobsUnifiedTopCardElement, toHeader, toPrimaryDescriptionLink, toPrimaryDescriptionText)
+import LinkedIn.JobsUnifiedTopCard (JobsUnifiedTopCardElement, TopCardInsight(..), TopCardInsightContent(..), _top_to_insights, toHeader, toPrimaryDescriptionLink, toPrimaryDescriptionText)
 import LinkedIn.UIElements.Types (UIElement(..), UIString(..))
 
 data JobOffer = JobOffer {
   title :: String,
   companyName :: String,
   companyLink :: String,
-  location :: Maybe String
+  location :: Maybe String,
+  remote :: Maybe String
 }
 
 derive instance Generic JobOffer _
@@ -26,11 +28,21 @@ fromUI card = ado
     companyName <- note "No company found" $ extractCompany link
     companyLink <- note "No company link found" $ extractCompanyLink link
   in
-    JobOffer { title, companyName, companyLink, location: extractLocation primaryDescText }
+    JobOffer {
+      title,
+      companyName,
+      companyLink,
+      location: extractLocation primaryDescText,
+      remote: extractJobRemote =<< jobInsight
+    }
   where
     header = toHeader card
     link = toPrimaryDescriptionLink card
     primaryDescText = toPrimaryDescriptionText card
+    jobInsight = findOf _top_to_insights (isIcon "job") card
+    isIcon icon = case _ of
+      TopCardInsight {icon: UIIcon i} -> i == icon
+      _ -> false
 
 extractTitle :: UIElement -> Maybe String
 extractTitle = case _ of
@@ -51,3 +63,8 @@ extractLocation :: UIElement -> Maybe String
 extractLocation = case _ of
   UIElement (UIStringDotSeparated _ (UIStringPlain str)) -> Just str
   _ -> Nothing
+
+extractJobRemote :: TopCardInsight UIElement -> Maybe String
+extractJobRemote = case _ of
+  TopCardInsight {content: TopCardInsightContentSecondary {primary: (UIElement (UIStringPlain str))}} -> Just str
+  _ -> Nothing

+ 9 - 1
src/LinkedIn/JobsUnifiedTopCard.purs

@@ -5,7 +5,7 @@ import Prelude
 import Control.Monad.Error.Class (throwError)
 import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
 import Data.Generic.Rep (class Generic)
-import Data.Lens (Lens', Prism', lens', prism', view)
+import Data.Lens (Lens', Prism', lens', prism', traversed, view)
 import Data.Lens.Record (prop)
 import Data.List.Types (NonEmptyList)
 import Data.Maybe (Maybe(..))
@@ -268,6 +268,14 @@ toPrimaryDescriptionText = view $ _top_card
   <<< _primary_description
   <<< prop (Proxy :: Proxy "text")
 
+_top_to_insights = _top_card
+  <<< prop (Proxy :: Proxy "insights")
+  <<< traversed
+  <<< traversed
+
+_insight_to_content = prop (Proxy :: Proxy "content")
+  <<< traversed
+
 _top_card ∷ forall a. Lens' (JobsUnifiedTopCardElement a) { actions ∷ Maybe (NonEmptyList (TopCardAction a)) , header ∷ a , insights ∷ Maybe (NonEmptyList (TopCardInsight a)) , primaryDescription ∷ TopCardPrimaryDescription a }
 _top_card = lens' \(JobsUnifiedTopCardElement c) -> Tuple c \c' -> JobsUnifiedTopCardElement c'