ArtDeco.purs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. module LinkedIn.ArtDeco where
  2. import Prelude
  3. import Data.Either (Either(..), hush)
  4. import Data.Generic.Rep (class Generic)
  5. import Data.List (List)
  6. import Data.List.NonEmpty (NonEmptyList)
  7. import Data.List.NonEmpty as NEL
  8. import Data.Maybe (Maybe)
  9. import Data.Show.Generic (genericShow)
  10. import LinkedIn (DetachedNode)
  11. import LinkedIn.Profile.Utils (toUIElement)
  12. import LinkedIn.Types (Parser)
  13. import LinkedIn.UIElements.Types (UIElement)
  14. import LinkedIn.Utils (queryAndDetachMany, queryAndDetachOne, queryManyAndParse, queryOneAndParse)
  15. import Parsing (ParseError)
  16. data ArtDecoPvsEntity = ArtDecoPvsEntity {
  17. side :: Unit,
  18. center :: ArtDecoCenter
  19. }
  20. data ArtDecoCenter = ArtDecoCenter {
  21. header :: ArtDecoCenterHeader,
  22. content :: ArtDecoCenterContent
  23. }
  24. data ArtDecoCenterHeader = ArtDecoCenterHeader {
  25. bold :: DetachedNode,
  26. normal :: Maybe DetachedNode,
  27. light :: Maybe (NonEmptyList DetachedNode)
  28. }
  29. data ArtDecoCenterContent = ArtDecoCenterContent (NonEmptyList ArtDecoPvsEntitySubComponent)
  30. data ArtDecoPvsEntitySubComponent = ArtDecoPvsEntitySubComponent (Maybe DetachedNode)
  31. derive instance Generic ArtDecoPvsEntitySubComponent _
  32. derive instance Eq ArtDecoPvsEntitySubComponent
  33. instance Show ArtDecoPvsEntitySubComponent where
  34. show = genericShow
  35. derive instance Generic ArtDecoCenterContent _
  36. derive instance Eq ArtDecoCenterContent
  37. instance Show ArtDecoCenterContent where
  38. show = genericShow
  39. derive instance Generic ArtDecoCenterHeader _
  40. derive instance Eq ArtDecoCenterHeader
  41. instance Show ArtDecoCenterHeader where
  42. show = genericShow
  43. derive instance Generic ArtDecoCenter _
  44. derive instance Eq ArtDecoCenter
  45. instance Show ArtDecoCenter where
  46. show = genericShow
  47. derive instance Generic ArtDecoPvsEntity _
  48. derive instance Eq ArtDecoPvsEntity
  49. instance Show ArtDecoPvsEntity where
  50. show = genericShow
  51. parseArtDecoPvsEntitySubComponent ∷ Parser ArtDecoPvsEntitySubComponent
  52. parseArtDecoPvsEntitySubComponent n = do
  53. content <- queryAndDetachOne "span[aria-hidden=true]" n
  54. pure $ Right $ ArtDecoPvsEntitySubComponent $ hush content
  55. parseArtDecoCenterContent ∷ Parser ArtDecoCenterContent
  56. parseArtDecoCenterContent n = do
  57. list <- queryManyAndParse ":scope > ul > li" parseArtDecoPvsEntitySubComponent n
  58. pure $ ado
  59. l <- list
  60. in ArtDecoCenterContent l
  61. parseArtDecoCenterHeader :: Parser ArtDecoCenterHeader
  62. parseArtDecoCenterHeader n = do
  63. bold <- queryAndDetachOne ":scope div.t-bold > span[aria-hidden=true]" n
  64. normal <- queryAndDetachOne ":scope span.t-normal:not(t-black--light) > span[aria-hidden=true]" n
  65. light <- queryAndDetachMany ":scope span.t-black--light > span[aria-hidden=true]" n
  66. pure $ ado
  67. b <- bold
  68. in ArtDecoCenterHeader {bold: b, normal: hush normal, light: hush light}
  69. parseArtDecoCenter :: Parser ArtDecoCenter
  70. parseArtDecoCenter n = do
  71. header <- queryOneAndParse ":scope > div" parseArtDecoCenterHeader n
  72. content <- queryOneAndParse ":scope > div.pvs-entity__sub-components" parseArtDecoCenterContent n
  73. pure $ ado
  74. h <- header
  75. c <- content
  76. in ArtDecoCenter {header: h, content: c}
  77. parseArtDecoPvsEntity :: Parser ArtDecoPvsEntity
  78. parseArtDecoPvsEntity n = do
  79. center <- queryOneAndParse ":scope > div.display-flex" parseArtDecoCenter n
  80. pure $ ado
  81. c <- center
  82. in ArtDecoPvsEntity {side: unit, center: c}
  83. toUI ∷
  84. ArtDecoPvsEntity
  85. → {
  86. bold' ∷ Either ParseError UIElement ,
  87. content' ∷ List (Either ParseError UIElement) ,
  88. light' ∷ Maybe (NonEmptyList (Either ParseError UIElement)) ,
  89. normal' ∷ Maybe (Either ParseError UIElement)
  90. }
  91. toUI (ArtDecoPvsEntity {
  92. center: ArtDecoCenter {
  93. header: ArtDecoCenterHeader {
  94. bold,
  95. normal,
  96. light
  97. },
  98. content: ArtDecoCenterContent subComponents
  99. }
  100. }) = {bold', content', normal', light'} where
  101. bold' = toUIElement bold
  102. content' :: List (Either ParseError UIElement)
  103. content' = map toUIElement subC
  104. where subC = NEL.catMaybes $ map (\(ArtDecoPvsEntitySubComponent c) -> c) subComponents :: List (DetachedNode)
  105. normal' :: Maybe (Either ParseError UIElement)
  106. normal' = toUIElement <$> normal
  107. light' :: Maybe (NonEmptyList (Either ParseError UIElement))
  108. light' = (map toUIElement) <$> light